//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdlib.h>
#include <EIC.h>
#pragma hdrstop

#include "uEtat.h"
#include "uRtf.h"
#include "uDocument.h"
#include "uComposant.h"
#include "Printer.h"
#include "uFncGDI.h"
//---------------------------------------------------------------------------
#define MODULE_TAG MODULE_TAG_COMPOSANT

#pragma package(smart_init)
#define NOMBRE_D_ELEMENTS     "Nombre d'éléments"
#define NUMERO_DE_PAGE        "Numéro de page"
#define NOMBRE_DE_PAGE        "Nombre de pages"
#define PAGE_X_SUR_Y          "Page x / y"
#define DATE                  "Date du jour"
//---------------------------------------------------------------------------
//---------------          LISTE DE COMPOSANTS         ----------------------
//---------------------------------------------------------------------------
#pragma warn -8037
TComposant* __fastcall TListOfComposants::GetItem( int Index)const
{ return (TComposant*)TList::Items[ Index]; };
#pragma warn .8037
__fastcall TListOfComposants::~TListOfComposants()
{
    if( m_hOld) _DeleteObject( TAGL, m_hOld);
    while( TList::Count)
    {
         delete ((TComposant *)TList::Items[ 0]);
         TList::Delete( 0);
    }
}

//---------------------------------------------------------------------------
enum Type_Composant_Pre_1_2 {
    cp_Rectangle_Pre_1_3=1,
    cp_Ellipse_Pre_1_3,
    cp_Texte_Pre_1_3,
    cp_Image_Pre_1_3,
    cp_Fleche_Pre_1_3,
    cp_Champ_Pre_1_3,
    cp_Tableau_Pre_1_3
};

__fastcall TListOfComposants::TListOfComposants( TBande *Bande, TFlux *f)
{
try{
    m_bCpExtensible = m_bTextesExtensible = false;
    Carac_Composant wType;
    TComposant      *Cp;
    if( Glob->bConception) m_hOld = ::_CreateRectRgn(TAGL, 0,0,0,0);

    m_BandeOwner = Bande;
    if( f && f->Size)
    {
        int  dw, dwOffsetFin = f->Position;  f->Lit( dw);  dwOffsetFin += dw;
        while( (f->Position != f->Size) && (dwOffsetFin != f->Position))
        {
            if( f->FileVersion >= FILE_VERSION( 1, 3))
                f->Lit( (DWORD)wType);
            else{
                WORD wType_Old;
                f->Lit( wType_Old);
                 switch( wType_Old)
                 {
                     case cp_Rectangle_Pre_1_3 : wType = Carac_Rectangle;    break;
                     case cp_Ellipse_Pre_1_3   : wType = Carac_Ellipse;      break;
                     case cp_Texte_Pre_1_3     : wType = Carac_Texte;        break;
                     case cp_Image_Pre_1_3     : wType = Carac_Image;        break;
                     case cp_Fleche_Pre_1_3    : wType = Carac_Fleche;       break;
                     case cp_Champ_Pre_1_3     : wType = Carac_Champ;        break;
                     case cp_Tableau_Pre_1_3   : wType = Carac_Tableau;     break;
                }
            }
            Cp = Add( wType, f);
            if( (wType & Carac_Texte) == Carac_Texte)
                m_bTextesExtensible |= (((TCpTexte*)Cp)->Presentation & Tx_Extensible);
        }
    }
}catch( EDocException &e){throw;}
CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------
TDocument*  __fastcall  TListOfComposants::GetDocOwner()const  {return m_BandeOwner->DocOwner; }
TEtat*      __fastcall  TListOfComposants::GetEtatOwner()const {return m_BandeOwner->EtatOwner;}
void __fastcall TListOfComposants::Enregistre( TFlux *f)
{
    int nOffsetDebut, nOffsetFin;
    nOffsetDebut = f->Position;    f->Ecrit( (int)0);
    for( int i = 0; i < TList::Count; i++)
    {
         f->Ecrit( (DWORD)((TComposant*)TList::Items[ i])->CaracCp);
         ((TComposant*)TList::Items[ i])->Enregistre( f);
    }
    nOffsetFin = f->Position;
    f->Position = nOffsetDebut;
    f->Ecrit( (int)nOffsetFin-nOffsetDebut);
    f->Position = nOffsetFin;
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::Draw( )
{
  try{
    if( !DocOwner->IsValidSupport() &&
        (DocOwner->Support != CanvasCALCUL_NB_PAGES)) return;
    TCanvas *canvas = m_BandeOwner->IsCanvasSupport();
    if( m_hOld && canvas && Glob->bConception)
    {
        ::_SetRectRgn( TAGL, m_hOld, 0,0,0,0);
        ::_GetClipRgn( TAGL, canvas->Handle, m_hOld);
    }
    TCoorRect rc;        m_BandeOwner->GetLimites( rc);
    TList* ListeCp = new TList();  GetComposantsIn( ListeCp, rc, m_BandeOwner, false);

    for( int i = 0; i < ListeCp->Count; i++)
    {
        TComposant *Cp = ((TComposant *)ListeCp->Items[ i]);
        if( !Glob->bConception &&
            (Cp->CaracCp & car_Graphic) &&
            (Cp->BandeOwner != Cp->BandeBs))
        {
            int nIndex = m_BandeOwner->EtatOwner->LstCpEnCours->IndexOf(Cp);
            if( (Cp->BandeOwner == m_BandeOwner) && (nIndex == -1))
                m_BandeOwner->EtatOwner->LstCpEnCours->Add( Cp);
            if( (Cp->BandeBs == m_BandeOwner) && (nIndex != -1))
                m_BandeOwner->EtatOwner->LstCpEnCours->Delete( nIndex);
        }

        if( DocOwner->Support == CanvasCALCUL_NB_PAGES)
        {   // si on calcul le nb de page seul les composants extensibles seront affichés
            TCpTexte *CpTexte = dynamic_cast<TCpTexte*>(Cp);
//            TCpChamp *CpChamp = dynamic_cast<TCpChamp*>(Cp);
//            if( CpChamp && (CpChamp->Type == tc_Calcule) || (CpChamp->TypeCalcul == tcalc_Info) )

            if( !CpTexte  || !(CpTexte->Presentation & Tx_Extensible))
                continue;
        }
        Cp->ClipAndCombineWith( m_hOld, m_BandeOwner);
        Cp->Dessine( m_BandeOwner);
    }
    delete ListeCp;
    if( m_hOld && canvas && Glob->bConception)
        ::_SelectClipRgn( TAGL, canvas->Handle, m_hOld);
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::DrawCpExtensibles( )
{
  try{
    TCoorRect rc;        m_BandeOwner->GetLimites( rc);
    TList* ListeCp = new TList(); GetComposantsIn( ListeCp, rc, m_BandeOwner, false);
    for( int i = 0; i < ListeCp->Count; i++)
    {
        TComposant *Cp = ((TComposant *)ListeCp->Items[ i]);
        if( (Cp->CaracCp & car_HauteurBande) && (Cp->CaracCp & car_Graphic))
        {
            Cp->Dessine( m_BandeOwner);
            continue;
        }

        TCpTexte *CpTexte = dynamic_cast<TCpTexte*>(Cp);
        if( (Cp->BandeOwner != m_BandeOwner) ||
            (CpTexte && (CpTexte->Presentation & Tx_Extensible) && (CpTexte->nLastCharPrint!=-1))            )
        {
            Cp->Dessine( m_BandeOwner);
        }
    }
    delete ListeCp;
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);

}
//---------------------------------------------------------------------------
bool __fastcall TListOfComposants::CpExtensiblesFinis()
{
  bool bRetour = true;
  try{
    TCoorRect rc;        m_BandeOwner->GetLimites( rc);
    TList* ListeCp = new TList(); GetComposantsIn( ListeCp, rc, m_BandeOwner, false);
    for( int i = 0; bRetour && i < ListeCp->Count; i++)
    {
        TCpTexte *CpTexte = dynamic_cast<TCpTexte*>((TComposant *)ListeCp->Items[ i]);
        if( (CpTexte && (CpTexte->Presentation & Tx_Extensible) && (CpTexte->nLastCharPrint!=-1))            )
        {
            if( CpTexte->nLastCharPrint != -1)
              bRetour = false;
        }
    }
    delete ListeCp;
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
  return bRetour;
}

//---------------------------------------------------------------------------
void __fastcall TListOfComposants::Calculs( )
{
  try{
    for( int i = TList::Count-1; i >= 0; i--)
    {
        TComposant *Cp = Items[ i];
        Cp->Calculs();
    }
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------
TComposant* __fastcall TListOfComposants::Add( Carac_Composant wType, const TCoordonnee &X, const TCoordonnee &Y)
{
    TComposant* Cp = NULL;
try{
#if cp_NbTypeCp != 7
    #error "Composant non reconnu"
#endif
    switch( wType & car_MskTypeCp)
    {
        case Carac_Rectangle : Cp = new TCpRectangle( this, X, Y);   break;
        case Carac_Ellipse   : Cp = new TCpEllipse( this, X, Y);     break;
        case Carac_Texte     : Cp = new TCpTexte( this, X, Y);       break;
        case Carac_Image     : Cp = new TCpImage( this, X, Y);       break;
        case Carac_Fleche    : Cp = new TCpFleche( this, X, Y);      break;
        case Carac_Champ     : Cp = new TCpChamp( this, X, Y);       break;
        case Carac_Tableau   : Cp = new TCpTableau( this, X, Y);     break;
        default : ASSERT( false);
    }
    TList::Add( (TObject*)Cp);
}CATCH_EXCEPTION( TAGL);
return Cp;
}

//---------------------------------------------------------------------------
TComposant* __fastcall TListOfComposants::Add( Carac_Composant wType, TFlux*f)
{
    TComposant* Cp = NULL;
    try{
#if cp_NbTypeCp != 7
    #error "Composant non reconnu"
#endif
    switch( wType & car_MskTypeCp)
    {
        case Carac_Rectangle : Cp = new TCpRectangle( this, f, wType);   break;
        case Carac_Ellipse   : Cp = new TCpEllipse( this, f, wType);     break;
        case Carac_Texte     : Cp = new TCpTexte( this, f, wType);       break;
        case Carac_Image     : Cp = new TCpImage( this, f, wType);       break;
        case Carac_Fleche    : Cp = new TCpFleche( this, f, wType);      break;
        case Carac_Champ     : Cp = new TCpChamp( this, f, wType);       break;
        case Carac_Tableau   : Cp = new TCpTableau( this, f, wType);     break;
        default : ASSERT( false);
    }
    TList::Add( (TObject*)Cp);
    }CATCH_EXCEPTION( TAGL);
    return Cp;
}
//---------------------------------------------------------------------------

TComposant* __fastcall TListOfComposants::Add( TComposant* Cp)
{
    TList::Add( (TObject*)Cp);
    Cp->m_ListCpOwner = this;
    return Cp;
}

//---------------------------------------------------------------------------
void __fastcall TListOfComposants::Delete( TComposant* Cp)
{
//    if( TList::IndexOf( (void*)Cp) != -1)
        TList::Delete( TList::IndexOf((void*)Cp));
    delete Cp;
}

//---------------------------------------------------------------------------
void __fastcall TListOfComposants::MettreEnAvantPlan( TComposant* Cp)
{
    TList::Move( TList::IndexOf((TObject*)Cp), TList::Count-1);
    Cp->Invalidate();
    m_BandeOwner->Modifie();
//    Draw();
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::MettreEnArrierePlan( TComposant* Cp)
{
    TList::Move( TList::IndexOf((TObject*)Cp), 0);
    Cp->Invalidate();
    m_BandeOwner->Modifie();
//    Draw();
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::GetComposantsIn( TList* ListeCp, const TCoorRect &rSelection, const TBande* BandeQuiDemande, bool bSelEntier)const
{
    /* Si le canvas n'est pas valide on ne va prendre en compte uniquement les
        composants qui peuvent changer la hauteur de la bande */
    bool        bSupportValide = m_BandeOwner->IsValidSupport();
    TComposant *Cp;
    TCpTexte   *CpTexte;
    RECT        rc, RcCp, rcSel;
    TCoorRect   cRc;
    if( !ListeCp) return;
    if( Glob->bConception)
        rcSel = rSelection.RECTPixels;

    if( (m_BandeOwner->Type != e_EnTete)/* && (m_BandeOwner->Type != e_Pied) && (m_BandeOwner->Type != e_ComplementPage)*/)
    {
        if( !Glob->bConception)
        {
            if( EtatOwner->LstCpEnCours)
                for( int i = 0; i < EtatOwner->LstCpEnCours->Count; i++)
                {
                    Cp = ((TComposant*)EtatOwner->LstCpEnCours->Items[ i]);
    // on accepte d'insérer uniquement dans le pied ou le complément si le composant commence dans l'entête
                    if( ( (BandeQuiDemande->Type == e_Pied) || (BandeQuiDemande->Type == e_ComplementPage)) &&
                        Cp->BandeOwner->Type != e_EnTete) continue;

                    if( Cp->BandeOwner != BandeQuiDemande)
                    {
                        if( (BandeQuiDemande->Type < e_Utilisateur) &&
                            (Cp->BandeOwner->Type < e_Utilisateur)  &&
                            (BandeQuiDemande != Cp->BandeBs))
                        {
    // on insère que dans les bandes comprises entre la bande owner et la bande basse
                            if( *BandeQuiDemande < *Cp->BandeOwner) continue;
                            if( *BandeQuiDemande > *Cp->BandeBs)    continue;
                        }
                        ListeCp->Add( Cp);
                    }
                    else                                   ListeCp->Extract( Cp);
                }
        }
        else if( m_BandeOwner->PreviousBande)
                m_BandeOwner->PreviousBande->LstComposants->GetComposantsIn( ListeCp, rSelection, BandeQuiDemande, bSelEntier);
    }

    bool bOK;
    for( int i = 0; i < TList::Count; i++)
    {
        Cp = Items[ i];
        if( !Glob->bConception && (/*!Cp->Visible ||voir EP Edition du relevé complet*/Cp->DansUneColonneViree()))
            continue;
        bOK = false;
        if( !bSupportValide && !( Cp->CaracCp & car_Graphic))
        {
            TCpChamp *CpChamp = dynamic_cast<TCpChamp*>( Cp);
            if( CpChamp && (CpChamp->BandeOwner == BandeQuiDemande) &&
                 (CpChamp->Type == tc_Calcule) &&
                 (CpChamp->TypeCalcul == tcalc_Colonne) &&
                 (CpChamp->TypeCalculCol == tCalcCol_Total))
            {
                CpChamp->InitValeur();
                continue;
            }
            CpTexte = dynamic_cast<TCpTexte*>( Cp);
            if( !CpTexte ||
                !(CpTexte->Presentation & Tx_Extensible) ) continue;
        }
        if( !bOK )
        {
            if( Glob->bConception)
            {
                Cp->GetTrueCoordonnees( cRc, m_BandeOwner);
                RcCp = cRc.RECTPixels;
                ::InflateRect( &RcCp, Glob->nRectifPourDessin, Glob->nRectifPourDessin);
                bOK = (  bSelEntier?
                           (::PtInRect( &rcSel, *((POINT*)&RcCp)) &&
                            ::PtInRect( &rcSel, *((POINT*)&RcCp.right)) )
                        :  ::IntersectRect( &rc, &RcCp, &rcSel)          );
            }else
            {
                bOK = !BandeQuiDemande || (Cp->BandeOwner == BandeQuiDemande);
                if( !bOK && ( Cp->CaracCp & car_Graphic))
                {
                    bOK = ( (*Cp->BandeOwner <= *BandeQuiDemande) &&
                            (*Cp->BandeBs >= *BandeQuiDemande)   );
                }
            }
        }
        if( bOK && (ListeCp->IndexOf( Cp) == -1) )
            ListeCp->Add( Cp);
    }
}
//---------------------------------------------------------------------------

TComposant* __fastcall TListOfComposants::GetComposant( const TCoordonnee &X, const TCoordonnee &Y, Type_CoinSelectionne &CoinCourant)const
{
    TComposant *Cp = NULL;
    POINT pt; pt.x = X.PixelsX; pt.y = Y.PixelsY;
    RECT  RcCp;
    TCoorRect cRc;
    CoinCourant = sel_Aucun;
    TCoorRect rc;        m_BandeOwner->GetLimites( rc);
    TList* ListeCp = new TList(); GetComposantsIn( ListeCp, rc, m_BandeOwner, false);

    for( int i = ListeCp->Count-1; i >= 0; i--)
    {
        Cp = ((TComposant *)ListeCp->Items[ i]);
        Cp->GetTrueCoordonnees( cRc, m_BandeOwner);
        RcCp = cRc.RECTPixels;
        HRGN h = Cp->GetRgnSel();
        if( ::PtInRect( &RcCp, pt) || ::PtInRegion( h, pt.x, pt.y))
        {
            if( ::PtInRegion( h, pt.x, pt.y))
            {
                     if( (pt.x >= RcCp.left  - 2) && (pt.x <= RcCp.left + 2))  CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_Gauche);
                else if( (pt.x >= RcCp.right - 2) && (pt.x <= RcCp.right + 2)) CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_Droit);
                else CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_HMilieu);


                     if( (pt.y >= RcCp.top  - 2)   && (pt.y <= RcCp.top + 2))    CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_Haut);
                else if( (pt.y >= RcCp.bottom - 2) && (pt.y <= RcCp.bottom + 2)) CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_Bas);
                else CoinCourant = (Type_CoinSelectionne)(CoinCourant | sel_VMilieu);
            }
            delete ListeCp;
            return Cp;
        }
    }
    delete ListeCp;
    return NULL;
}
//---------------------------------------------------------------------------

TComposant* __fastcall TListOfComposants::GetComposant( const AnsiString &s)const
{
    for( int i = TList::Count-1; i >= 0; i--)
    {
        TCpChamp *CpC = dynamic_cast<TCpChamp *>(Items[ i]);
        if( CpC && (CpC->Nom == s))
            return CpC;
        else
        {
            TCpTableau *CpT = dynamic_cast<TCpTableau *>(Items[ i]);
            if( CpT && CpT->Nom == s)
                return CpT;
        }
    }
    return NULL;
}
//---------------------------------------------------------------------------
void __fastcall TListOfComposants::InvalideComposantsAttacheA( const AnsiString &ChpAttache)
{
    for( int i = 0; i < TList::Count; i++)
    {
        if( ((TComposant *)TList::Items[ i])->IsComposantAttacheA( ChpAttache))
            ((TComposant *)TList::Items[ i])->Invalidate();
    }
}
//---------------------------------------------------------------------------
void __fastcall TListOfComposants::NettoieComposantsAttacheA( const AnsiString &ChpAttache)
{
    for( int i = 0; i < TList::Count; i++)
    {
        if( ((TComposant *)TList::Items[ i])->IsComposantAttacheA( ChpAttache))
        {
            TCpTexte *c = dynamic_cast<TCpTexte *>((TComposant *)TList::Items[ i]);
            if( c)
//                m_nLastCharPrint
                c->TComposant::Nettoie();
//                m_nLastCharPrint
            else
                ((TComposant *)TList::Items[ i])->Nettoie();
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::GetComposants( enum TypesComposants TypeCp, TStrings *LstCp)const
{
    for( int i = TList::Count-1; i >= 0; i--)
    {
        TComposant *Cp = Items[ i];
#if ETAT_Cp_MAX != 2
    #error "type de champ non reconnu"
#endif
        if( LstCp->IndexOfObject( Cp)==-1)
        {
            switch( TypeCp)
            {
                case ETAT_Cp_Champs_Nommes :
                {
                    TCpChamp *CpC = dynamic_cast<TCpChamp *>(Items[ i]);
                    if( CpC && !CpC->Nom.IsEmpty()) LstCp->AddObject( CpC->Nom, CpC);
                }break;
                case ETAT_Cp_Tableaux_Nommes :
                {
                    TCpTableau *CpT = dynamic_cast<TCpTableau *>(Items[ i]);
                    if( CpT && !CpT->Nom.IsEmpty()) LstCp->AddObject( CpT->Nom, CpT);
                }break;
                case ETAT_Cp_Textes_Saisis :
                {
                    AnsiString Nom;
                    TCpChamp *CpC = dynamic_cast<TCpChamp *>(Items[ i]);
                    if( CpC) Nom = CpC->Nom;
                    TCpTableau *CpT = dynamic_cast<TCpTableau *>(Items[ i]);
                    if( CpT) Nom = CpT->Nom;
                    //                TCpChamp *CpC = dynamic_cast<TCpChamp *>(Items[ i]);
                    TCpTexte *CpTexte = dynamic_cast<TCpTexte *>(Items[ i]);
                    if( (CpTexte != NULL) ) LstCp->AddObject( Nom, Cp);
                }break;
                default : ASSERT( FALSE);
            }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::GetCpCalc( TList* ListeCpCalcCol, TList* ListeCpCalcLigne, TList* LstCpExtensibles, bool &bCpNbPages)const
{
    TCpChamp *CpChamp;
    TCpTexte *CpTexte;
    TCoorRect cRc;

    for( int i = TList::Count-1; i >= 0; i--)
    {
        CpTexte = dynamic_cast<TCpTexte*>(Items[ i]);
        if( CpTexte && (CpTexte->Presentation & Tx_Extensible))
        {
            LstCpExtensibles->Add( CpTexte);
        }

        CpChamp = dynamic_cast<TCpChamp*>(Items[ i]);
        if( CpChamp)
        {
            switch( CpChamp->TypeCalcul )
            {
                case tcalc_Colonne : ListeCpCalcCol->Add( CpChamp); break;
                case tcalc_Ligne   : ListeCpCalcLigne->Add( CpChamp); break;
                case tcalc_Info    : if( !bCpNbPages &&
                                         ((CpChamp->Champ == NOMBRE_DE_PAGE) ||
                                          (CpChamp->Champ == PAGE_X_SUR_Y)   ) )
                                          bCpNbPages = true;
                                     break;
            }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TListOfComposants::Nettoie( )
{
  try{
    for( int i = TList::Count-1; i >= 0; i--)
    {
        ((TComposant *)TList::Items[ i])->Nettoie();

    }
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
}
void        __fastcall TListOfComposants::AppliqueStyles( )
{
  try{
    if( !DocOwner->Styles->Count) return;
    for( int i = TList::Count-1; i >= 0; i--)
    {
        ((TComposant *)TList::Items[ i])->AppliqueStyle();

    }
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
}

//---------------------------------------------------------------------------
bool __fastcall TListOfComposants::WantedHeight( TCoordonnee &HeightMin, TCoordonnee &HeightMax, bool &TiensElleEstEnCours)const
{
  bool bReturn = false, TiensIlEstEnCours = false;
  try{
    TiensElleEstEnCours = false;
    if( m_bCpExtensible)
    {
        TCoordonnee HeightCpMin, HeightCpMax;
        HeightMin = m_BandeOwner->Hauteur;
        HeightMax = HeightMin;
        HeightCpMin.PixelsY = 0;
        HeightCpMax.PixelsY = 0;
        for( int i = TList::Count-1; i >= 0; i--)
        {
            TCpTexte *Cp = dynamic_cast<TCpChamp*>(Items[ i]);
            if( !Cp)
                Cp = dynamic_cast<TCpTexte*>(Items[ i]);
            if( Cp && ( Cp->Presentation & Tx_Extensible)           )
            {
                if( !Glob->bConception && Cp->DansUneColonneViree())
                    continue;
                bool b = Cp->WantedToChangeHeightOfBande( HeightCpMin, HeightCpMax, TiensIlEstEnCours);
                TiensElleEstEnCours |= TiensIlEstEnCours;
                if( b && ((HeightCpMax > HeightMax)  || TiensIlEstEnCours))
                {
                    HeightMin = HeightCpMin;
                    HeightMax = HeightCpMax;
                    bReturn = true;
                }
            }
        }
    }
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
  return bReturn;
}

//---------------------------------------------------------------------------
int __fastcall CompareCpChamp(void * Item1, void * Item2)
{
    TCpChamp *c1 = (TCpChamp*)Item1, *c2 = (TCpChamp*)Item2;
    int n1=5, n2=5;
    switch( c1->Type)
    {
        case tc_Programme    : n1 = 4; break;
        case tc_BaseDeDonnee : n1 = 1; break;
        case tc_Calcule :
                switch ( c1->TypeCalcul)
                {
                    case tcalc_Ligne   : n1 = 2; break;
                    case tcalc_Colonne : n1 = 3; break;
                    case tcalc_Info    : n1 = 0; break;
                }
            break;
    }
    switch( c2->Type)
    {
        case tc_Programme    : n2 = 4; break;
        case tc_BaseDeDonnee : n2 = 1; break;
        case tc_Calcule :
                switch ( c2->TypeCalcul)
                {
                    case tcalc_Ligne   : n2 = 2; break;
                    case tcalc_Colonne : n2 = 3; break;
                    case tcalc_Info    : n2 = 0; break;
                }
            break;
    }

    return (n1 < n2)? -1 : ((n1 == n2)? 0 : 1);

}

void __fastcall TListOfComposants::InitValeurs( )
{
  try{
#if tc_Max != 4
    #error "type de champ non reconnu"
#endif
#if tcalc_Max != 3
    #error "type de calcul de champ non reconnu"
#endif
    TCpChamp *cC;
/*    TCpTableau *cT;
    TList *Lst = new TList();*/
    bool bChpExtensible = false;
    for( int i = TList::Count-1; i >= 0; i--)
    {
        cC = dynamic_cast<TCpChamp*>((TObject*)TList::Items[ i]);
        if( cC) { cC->InitValeur(); bChpExtensible |= (cC->Presentation & Tx_Extensible);}
   /*     cT = dynamic_cast<TCpTableau*>(Items[ i]);
        if( cT) cT->InitValeur();*/
    }                       
    m_bCpExtensible = m_bTextesExtensible | bChpExtensible;
/*    Lst->Sort( CompareCpChamp);
    for( int i = 0; i < TList::Count; i++)//Lst->Count-1; i >= 0; i--)
    {
        cC = (TCpChamp*)(Lst->Items[ i]);
        if( cC) cC->InitValeur();
    }
    delete Lst;*/
  }
  CATCH_Annul_TropDeCol_Abort( )
  CATCH_EXCEPTION( TAGL);
}

TCpChamp*   __fastcall TListOfComposants::GetCpChamp( const AnsiString &s)const
{
    TCpChamp *c;

    for( int i = TList::Count-1; i >= 0; i--)
    {
        c = dynamic_cast<TCpChamp*>(Items[ i]);
        if( c && c->Nom == s)
            return c;
    }
    return NULL;
}
TCpTableau*   __fastcall TListOfComposants::GetCpTableau( const AnsiString &s)const
{
    TCpTableau *c;

    for( int i = TList::Count-1; i >= 0; i--)
    {
        c = dynamic_cast<TCpTableau*>(Items[ i]);
        if( c && c->Nom == s)
            return c;
    }
    return NULL;
}

TComposant* __fastcall  TListOfComposants::GetPrecedentSuivant( bool bPrec, const TComposant* Cp)const
{
    TComposant* CpReturn = NULL;
    if( TList::Count > 0)
    {
        if( Cp == NULL)
            CpReturn = Items[ bPrec?TList::Count-1:0];
        else
        {
            int nIndex = IndexOf( Cp);
            if( bPrec ? (nIndex > 0) : (nIndex < Count-1))
                CpReturn = Items[ nIndex + (bPrec?-1:+1)];
            else
                CpReturn = m_BandeOwner->LstBandesOwner->GetCpPrecedentSuivant( bPrec, m_BandeOwner);
        }
    }
    return CpReturn;
}

TComposant* __fastcall  TListOfComposants::GetChampEnDessous( const TComposant* CpRef)const
{
    RECT r1, r2;
    TCoorRect rc, rcRef;            m_BandeOwner->GetLimites( rc);
    TList* ListeCp = new TList();   GetComposantsIn( ListeCp, rc, m_BandeOwner, false);
    TComposant *CpReturn = NULL;
    CpRef->GetTrueCoordonnees( rcRef, m_BandeOwner);
    for( int i = ListeCp->IndexOf( (void*)CpRef)-1; i >= 0; i--)
    {
        CpReturn = ((TComposant *)ListeCp->Items[ i]);
        CpReturn->GetTrueCoordonnees( rc, m_BandeOwner);
        r1 = rcRef.RECTTwips; r2 = rc.RECTTwips;
        if( ::IntersectRect( &r1, &r1, &r2)) break;
        else                                 CpReturn = NULL;
    }
    delete ListeCp;
    return CpReturn;
}
void        __fastcall TListOfComposants::DeplaceTout( const TCoordonnee &c)
{
    for( int i = TList::Count-1; i >= 0; i--)
    {
        TComposant *Cp = dynamic_cast<TComposant*>(Items[ i]);
        Cp->m_PointHtG.y -= c;
        Cp->m_PointBsD.y -= c;
    }
}



//---------------------------------------------------------------------------
//----------------              COMPOSANT             -----------------------
//---------------------------------------------------------------------------

__fastcall TComposant::~TComposant()
{
    if( m_hSel)      ::_DeleteObject( TAGL, m_hSel);
    if( DocOwner->bEnCoursDestruction) return;
    Modifie();
    Invalidate( );
//    m_PointHtG.x + DocOwner->LargBarreGauche, m_BandeOwnerG->Top + m_PointHtG.y, m_PointBsD.x + DocOwner->LargBarreGauche, m_BandeBsD->Top + m_PointBsD.y
    if( m_bSelected) InvalidateSelect();
}
//---------------------------------------------------------------------------

__fastcall TComposant::TComposant( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                      : TMyObject( )
{
    m_ListCpOwner     = ListCp;
    m_NumColonne       = -1;

    m_hSel           = NULL;
    m_bSelected      = false;
    m_CaracCp        = (Carac_Composant)(car_Base | CaracCp | car_LargeurStd | car_HauteurStd);
//    m_eTypeComposant = eTypeComposant;

    m_eTypeBandeBs = BandeOwner->Type;
    m_wNiveauBs    = BandeOwner->Niveau;

    m_PointHtG.x = X - LargBarreGauche - DocOwner->Marges.Left;
    m_PointHtG.y = Y - BandeOwner->Top;
    m_PointBsD.x.PixelsX = m_PointHtG.x.PixelsX+1;
    m_PointBsD.y.PixelsY = m_PointHtG.y.PixelsY+1;
    m_GetTrueCoorHtG.x.Twips   = -1;
    m_GetTrueCoorHtG.y.Twips   = -1;
    m_GetTrueCoorBsD.x.Twips   = -1;
    m_GetTrueCoorBsD.y.Twips   = -1;
    m_DansUneColonneViree = -1;

    m_PenStyle   = psSolid;
    m_PenWidthGauche = 0.75;
    m_PenWidthHaut   = 0.75;
    m_PenWidthDroit  = 0.75;
    m_PenWidthBas    = 0.75;
    m_MoitieGauche   = false;
    m_MoitieDroit    = false;

    m_PenColor   = DocOwner->ColorDefaut;

    m_BrushStyle = bsClear;
    m_BrushColor = clWhite;
    m_bVisible = true;
    m_VisibleCalc = true;
    m_Style = EmptyStr;


}
//---------------------------------------------------------------------------

__fastcall TComposant::TComposant( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                      : TMyObject( )
{
    try{
        m_ListCpOwner     = ListCp;
        m_NumColonne       = m_NumLigne = -1;
        m_GetTrueCoorHtG.x.Twips   = -1;
        m_GetTrueCoorHtG.y.Twips   = -1;
        m_GetTrueCoorBsD.x.Twips   = -1;
        m_GetTrueCoorBsD.y.Twips   = -1;
        m_DansUneColonneViree = -1;

        m_hSel             = NULL;
        m_bSelected        = false;
        m_CaracCp          = (Carac_Composant)(car_Base | CaracCp);
    //    m_eTypeComposant   = eTypeComposant;
        m_bForceBrushStyle = false;
        m_BrushStyle       = bsSolid;
        m_BrushColor       = clWhite;
        m_bVisible = true;
        m_VisibleCalc      = true;
        if( f)
        {
            m_PointHtG.Lit( f);
            WORD w;
            f->Lit( w); m_eTypeBandeBs = (TYPE_BANDE)w;
            f->Lit( m_wNiveauBs);
            m_PointBsD.Lit( f);
            if( !(m_CaracCp & car_Graphic))
            {
                m_eTypeBandeBs = BandeOwner->Type;
                m_wNiveauBs = BandeOwner->Niveau;
            }
            if( (BandeOwner->Type != e_Pied) && (m_eTypeBandeBs == e_Pied) && (m_wNiveauBs==1))
            {
                if( BandeOwner->OwnerDocument)
                    DocOwner->CpEndsInPied |= true;
                else
                    EtatOwner->CpEndsInPied |= true;
            }
            f->Lit( m_PenStyle);
            if( f->FileVersion >= FILE_VERSION( 0, 2))
            {
                f->Lit( m_PenWidthGauche);
                f->Lit( m_PenWidthHaut);
                f->Lit( m_PenWidthDroit);
                f->Lit( m_PenWidthBas);
                if( m_PenWidthGauche>10) m_PenWidthGauche=0.;
                if( m_PenWidthHaut>10) m_PenWidthHaut=0.;
                if( m_PenWidthDroit>10) m_PenWidthDroit=0.;
                if( m_PenWidthBas>10) m_PenWidthBas=0.;
            }else{
                int Width;
                f->Lit( Width); m_PenWidthGauche = Width;
                f->Lit( Width); m_PenWidthHaut   = Width;
                f->Lit( Width); m_PenWidthDroit  = Width;
                f->Lit( Width); m_PenWidthBas    = Width;
            }
            f->Lit( m_MoitieGauche);
            f->Lit( m_MoitieDroit);
            f->Lit( m_PenColor);

            f->Lit( m_BrushStyle);
            f->Lit( m_BrushColor);
            if( f->FileVersion >= FILE_VERSION( 1, 5))
            {
                if( m_CaracCp & car_LargeurColonne)
                    f->Lit( m_NumColonne);
                if( m_CaracCp & (car_LargeurColonne | car_ColleGauche | car_ColleDroite))
                    f->Lit( m_NomChpHorzAssocie);
            }
            else if( f->FileVersion >= FILE_VERSION( 0, 6))
            {
                f->Lit( m_NumColonne);
                if( m_NumColonne != -1)
                    f->Lit( m_NomChpHorzAssocie);
            }
            if( f->FileVersion >= FILE_VERSION( 1, 9))
            {
                if( m_CaracCp & car_HauteurLigne)
                    f->Lit( m_NumLigne);
                if( m_CaracCp & (car_HauteurLigne | car_ColleHaut | car_ColleBas))
                    f->Lit( m_NomChpVertAssocie);
            }
            if( f->FileVersion >= FILE_VERSION( 1, 13))
            {
                f->Lit( m_Style);
            }
        }
        if( !(m_CaracCp & car_MskLargeur))
        {
            if( !m_NomChpHorzAssocie.IsEmpty() && m_NumColonne != -1)
                m_CaracCp = (Carac_Composant)(m_CaracCp | car_LargeurColonne);
            else
                m_CaracCp = (Carac_Composant)(m_CaracCp | car_LargeurStd);
        }
        if( !(m_CaracCp & car_MskHauteur))
            m_CaracCp = (Carac_Composant)(m_CaracCp |car_HauteurStd);
    }CATCH_EXCEPTION( TAGL)
}
//---------------------------------------------------------------------------

void __fastcall TComposant::Enregistre( TFlux *f)const
{
    m_PointHtG.Enregistre( f);
    f->Ecrit( (WORD)m_eTypeBandeBs);
    f->Ecrit( m_wNiveauBs);
    m_PointBsD.Enregistre( f);

    f->Ecrit( m_PenStyle);
    f->Ecrit( m_PenWidthGauche);
    f->Ecrit( m_PenWidthHaut);
    f->Ecrit( m_PenWidthDroit);
    f->Ecrit( m_PenWidthBas);
    f->Ecrit( m_MoitieGauche);
    f->Ecrit( m_MoitieDroit);
    f->Ecrit( m_PenColor, DocOwner->ColorDefaut);

    f->Ecrit( m_BrushStyle);
    f->Ecrit( m_BrushColor, (TColor)-1);
    if( m_CaracCp & car_LargeurColonne)
        f->Ecrit( m_NumColonne);
    if( m_CaracCp & (car_LargeurColonne | car_ColleGauche | car_ColleDroite))
        f->Ecrit( m_NomChpHorzAssocie);
    if( m_CaracCp & car_HauteurLigne)
        f->Ecrit( m_NumLigne);
    if( m_CaracCp & (car_HauteurLigne | car_ColleHaut | car_ColleBas))
        f->Ecrit( m_NomChpVertAssocie);
    f->Ecrit( m_Style);
}
//---------------------------------------------------------------------------
TDocument* __fastcall TComposant::GetDocOwner()const   { return m_ListCpOwner->DocOwner;  }
TEtat*     __fastcall TComposant::GetEtatOwner()const  { return m_ListCpOwner->EtatOwner; }
TBande*    __fastcall TComposant::GetBandeOwner()const { return m_ListCpOwner->BandeOwner;}
//---------------------------------------------------------------------------
TBande* __fastcall TComposant::GetBandeBs()const
{
    if( !Glob->bConception && m_BdBas)
        return m_BdBas;
    if( m_CaracCp & car_Graphic)
    {
        TBande *b;
        switch( m_eTypeBandeBs)
        {
            case e_Principal    : b = EtatOwner->GetBandeDetail(); break;
            case e_DebutColonne : b = EtatOwner->GetBandeDebColonne(); break;
            case e_FinColonne   : b = EtatOwner->GetBandeFinColonne(); break;
            default             : b = EtatOwner->GetBande( m_eTypeBandeBs, m_wNiveauBs); break;
        }
//        ASSERT( b);
        if( !b) b = BandeOwner;
        (TBande*)m_BdBas = b;
        return b;
    }
    // ce n'est pas un composant graphique  : il ne pêut être que sur une seule bande
    (TBande*)m_BdBas = BandeOwner;
    return BandeOwner;
}

//---------------------------------------------------------------------------
void __fastcall TComposant::Dessine( const TBande* BandeADessiner)
{
    #define TAILLE_TRAIT  5
    if( Glob->bConception)
    {
        TCanvas *c = IsCanvasSupport();
        if( !c) return;
        TCoorRect Rc; GetTrueCoordonnees( Rc);
        int Gauche = min( Rc.Left.PixelsX + TAILLE_TRAIT,   Rc.Right.PixelsX),
            Droit  = max( Rc.Right.PixelsX - TAILLE_TRAIT,  Rc.Left.PixelsX),
            Haut   = min( Rc.Top.PixelsY + TAILLE_TRAIT,    Rc.Bottom.PixelsY),
            Bas    = max( Rc.Bottom.PixelsY - TAILLE_TRAIT, Rc.Top.PixelsY);

        c->Pen->Style = psSolid;
        c->Pen->Width = 1;
        c->MoveTo( Rc.Left.PixelsX,  Haut);
        c->Pen->Color = ( m_CaracCp & (car_ColleGauche | car_LargeurColonne |car_LargeurEtat ))? clRed : clBlack;
        c->LineTo( Rc.Left.PixelsX,  Rc.Top.PixelsY);
        c->Pen->Color = ( m_CaracCp & (car_ColleHaut   | car_HauteurBande   |car_HauteurLigne))? clRed : clBlack;
        c->LineTo( Gauche,          Rc.Top.PixelsY);

        c->MoveTo( Droit,           Rc.Top.PixelsY);
        c->LineTo( Rc.Right.PixelsX, Rc.Top.PixelsY);
        c->Pen->Color = ( m_CaracCp & (car_ColleDroite | car_LargeurColonne |car_LargeurEtat ))? clRed : clBlack;
        c->LineTo( Rc.Right.PixelsX, Haut);

        c->MoveTo( Rc.Right.PixelsX, Bas);
        c->LineTo( Rc.Right.PixelsX, Rc.Bottom.PixelsY);
        c->Pen->Color = ( m_CaracCp & (car_ColleBas    | car_HauteurBande   |car_HauteurLigne))? clRed : clBlack;
        c->LineTo( Droit,           Rc.Bottom.PixelsY);

        c->MoveTo( Gauche,          Rc.Bottom.PixelsY);
        c->LineTo( Rc.Left.PixelsX,  Rc.Bottom.PixelsY);
        c->Pen->Color = ( m_CaracCp & (car_ColleGauche | car_LargeurColonne |car_LargeurEtat ))? clRed : clBlack;
        c->LineTo( Rc.Left.PixelsX,  Bas);

        if( m_bSelected)
            DrawSelect( clBlack);
    }
}

//---------------------------------------------------------------------------
void __fastcall TComposant::Calculs( )
{
}

//---------------------------------------------------------------------------
void __fastcall TComposant::SetPenColor( TColor color)
{
    TColor c = (color == DocOwner->ColorDefaut)? (TColor)-1 : color;
    if( c == m_PenColor) return;
    m_PenColor = c;
    Modifie();
}
//---------------------------------------------------------------------------
bool __fastcall TComposant::IsHautInBande( const TBande* b)const { return (b == BandeOwner); }
//---------------------------------------------------------------------------
bool __fastcall TComposant::IsBasInBande( const TBande* b)const  { return (b->Type == m_eTypeBandeBs) && (b->Niveau == m_wNiveauBs); }
//---------------------------------------------------------------------------
bool   __fastcall TComposant::DansUneColonneViree( )const
{
    if(m_CaracCp & car_LargeurColonne)
    {
        if( m_DansUneColonneViree != -1)
            return m_DansUneColonneViree;
        *((short*)&m_DansUneColonneViree) = false;
        if( !m_NomChpHorzAssocie.IsEmpty() && m_NumColonne != -1)
        {
            int nIndex = EtatOwner->LstCpTableau?EtatOwner->LstCpTableau->IndexOf(m_NomChpHorzAssocie):0;
            if( nIndex != -1)
            {
                TCpTableau *CpTab;
                if( EtatOwner->LstCpTableau)
                    CpTab = dynamic_cast<TCpTableau*>(EtatOwner->LstCpTableau->Objects[nIndex]);
                else{
                    TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpHorzAssocie);
                    if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpHorzAssocie);
                    CpTab = dynamic_cast<TCpTableau*>(Cp);
                }
                if( CpTab)
                {
//                    TCoorRect Rc;
//                    CpTab->GetTrueCoordonnees(Rc, BandeOwner); //init du cp tableau
                    int nColDeb, nColFin;
                    nColDeb = nColFin = LOBYTE(m_NumColonne);
                    nColFin = min( nColFin + HIBYTE(m_NumColonne), CpTab->ColonnesCount-1);

                    if( nColDeb < CpTab->ColonnesCount )
                    {
                        COLONNE *cDeb = CpTab->GetColonne( nColDeb);
                        while( !cDeb->Visible && (nColDeb < nColFin))
                        {
                            nColDeb++;
                            cDeb = CpTab->GetColonne( nColDeb);
                        }
                        if( !cDeb->Visible)
                        {
//                            *((bool*)&m_VisibleCalc) = false;
                            *((short*)&m_DansUneColonneViree) = true;
                        }
                    }else goto Fin;
                }else goto Fin;
            }else goto Fin;
        }
    }
Fin:
    return false;
}
//---------------------------------------------------------------------------
#define LARGEUR_SANS_MARGE_GAUCHE  EtatOwner->Largeur  - DocOwner->Marges.Left
void __fastcall TComposant::GetTrueCoordonnees( TCoorPoint &ptHtG, TCoorPoint &ptBsD, const TBande* BandeADessiner)const
{
    const TBande *BandeRef = BandeADessiner ? BandeADessiner :
                                EtatOwner->BandeEnCours ? EtatOwner->BandeEnCours
                                    : BandeOwner;
    TCoordonnee bdRefTop = BandeRef->Top;
    if( !Glob->bConception &&
        (m_bdDess == BandeADessiner) &&
        (m_bdHautTop == bdRefTop) &&
        (LARGEUR_SANS_MARGE_GAUCHE == m_LargTrueCoor) &&
        (m_GetTrueCoorHtG.x.Twips != -1) &&
        (m_GetTrueCoorHtG.y.Twips != -1))
    {
        ptHtG = m_GetTrueCoorHtG;
        ptBsD = m_GetTrueCoorBsD;
        return;
    }

    m_bdDess = NULL;
    m_bdHautTop  = 0;
    try{
    ptHtG.x = -10; ptBsD.x = -10; ptHtG.y = -10; ptBsD.y = -10;
    if( !Glob->bConception && !GetVisible()) return;

    if( (m_GetTrueCoorHtG.y.Twips != -1) && (m_bdHautTop == bdRefTop) && (m_bdDess == BandeADessiner))
    {
        ptHtG.y = m_GetTrueCoorHtG.y;
        ptBsD.y = m_GetTrueCoorBsD.y;
    }else
    {
        TCoorRect rMargeBandeRef;
        BandeRef->GetMarges( rMargeBandeRef);
        m_DecalInterneBas = 0;
        if(m_CaracCp & car_HauteurLigne)
        {
            if( !m_NomChpVertAssocie.IsEmpty() && m_NumLigne != -1)
            {
                int nIndex = EtatOwner->LstCpTableau?EtatOwner->LstCpTableau->IndexOf(m_NomChpVertAssocie):0;
                if( nIndex != -1)
                {
                    TCpTableau *CpTab;
                    if( EtatOwner->LstCpTableau)
                        CpTab = dynamic_cast<TCpTableau*>(EtatOwner->LstCpTableau->Objects[nIndex]);
                    else{
                        TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpVertAssocie);
                        if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpVertAssocie);
                        CpTab = dynamic_cast<TCpTableau*>(Cp);
                    }
                    if( CpTab)
                    {
                        int nLigneDeb, nLigneFin;
                        nLigneDeb = LOBYTE(m_NumLigne);
                        nLigneFin = min( nLigneDeb + HIBYTE(m_NumLigne), CpTab->NbLignes-1);

                        if( nLigneDeb == CpTab->NbLignes)
                        {
                            TCoorRect Rc;
                            CpTab->GetTrueCoordonnees( Rc, BandeADessiner);
                            ptHtG.y = Rc.Top;
                            if( CpTab->PenWidthHaut) ptHtG.y.PixelsR[Glob->ResolEcran] += AspectY( CpTab->PenWidthHaut).PixelsR[Glob->ResolEcran];
                            ptBsD.y = Rc.Bottom;
                            if( CpTab->PenWidthBas)  ptHtG.y.PixelsR[Glob->ResolEcran] -= AspectY( CpTab->PenWidthBas).PixelsR[Glob->ResolEcran];
                        }else if( nLigneDeb < CpTab->NbLignes )
                        {
                            CpTab->GetLigne( nLigneDeb, ptHtG.y, ptBsD.y);
                            if( nLigneDeb != nLigneFin)
                            {
                                TCoordonnee c;
                                CpTab->GetLigne( nLigneFin, c, ptBsD.y);
                            }
/*                            ptHtG.y.PixelsR[Glob->ResolEcran] += AspectX( CpTab->PenWidthHaut).PixelsR[Glob->ResolEcran];
                            ptBsD.y.PixelsR[Glob->ResolEcran] -= AspectX( CpTab->PenWidthBas).PixelsR[Glob->ResolEcran];*/
                        }else goto Corr_Vert_Sans_Tableau;
                    }else goto Corr_Vert_Sans_Tableau;
                }else goto Corr_Vert_Sans_Tableau;
            }
        }else if( m_CaracCp & car_HauteurBande)
        {
            ptHtG.y = rMargeBandeRef.Top;
            if( Glob->bConception)
            {
              TCoorRect rMargeBandeBs;
              BandeBs->GetMarges( rMargeBandeBs);
              ptBsD.y = rMargeBandeBs.Bottom;
            }else
              ptBsD.y = rMargeBandeRef.Bottom;
            m_DecalInterneBas = TCoordonnee::PixY(1) - TCoordonnee::Pix(1,Glob->ResolEcran);
        }else if( m_CaracCp & car_ColleHaut)
        {

            bool bRectifHt = false, bRectifBs = false;
            if( !m_NomChpVertAssocie.IsEmpty())
            {
                TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpVertAssocie);
                if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpVertAssocie);
                if( !dynamic_cast<TCpTableau*>(Cp) && !dynamic_cast<TCpChamp*>(Cp))  goto Corr_Vert_Sans_Tableau;
                if( !Cp->GetVisible()) return;
                ptHtG.y = Cp->BandeBs->Top + Cp->Bas;
                bRectifHt = true;
            }else
            {
                ptHtG.y = rMargeBandeRef.Top;
            }

            if( BandeHt == BandeBs )      {ptBsD.y = ptHtG.y + Hauteur; bRectifBs = bRectifHt; ASSERT( BandeHt == BandeRef);}
            else if( BandeRef == BandeBs) ptBsD.y = bdRefTop + m_PointBsD.y;
            else                          ptBsD.y = bdRefTop + BandeRef->Hauteur;
            if( bRectifHt)
                ptHtG.y += TCoordonnee::Pixels2TwipsY(1);
            if( bRectifBs)
                ptBsD.y += TCoordonnee::Pixels2Twips(1, Glob->ResolEcran);

        }else if( m_CaracCp & car_ColleBas)
        {
            bool bRectifHt = false, bRectifBs = false;
            if( !m_NomChpVertAssocie.IsEmpty())
            {
                TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpVertAssocie);
                if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpVertAssocie);
                if( !dynamic_cast<TCpTableau*>(Cp) && !dynamic_cast<TCpChamp*>(Cp))  goto Corr_Vert_Sans_Tableau;
                if( !Cp->GetVisible()) return;
                ptBsD.y = Cp->BandeHt->Top + Cp->Haut;// - TCoordonnee:: Pixels2Twips(1, Glob->ResolEcran);
                bRectifBs = true;
            }else
            {
                ptBsD.y = rMargeBandeRef.Bottom;// - TCoordonnee::Pixels2TwipsY(Glob->bConception? HAUTEUR_ENTRE_BANDES:0);
            }
            if( BandeHt == BandeBs )      {ptHtG.y = ptBsD.y - Hauteur; bRectifHt = bRectifBs; /*ASSERT( BandeHt == BandeRef);*/}
            else if( BandeRef == BandeHt) ptHtG.y = bdRefTop + m_PointHtG.y;
            else                          ptHtG.y = bdRefTop;
            if( bRectifBs)
                ptBsD.y -= TCoordonnee::Pixels2TwipsY(1);
            if( bRectifHt)
                ptHtG.y -= TCoordonnee::Pixels2Twips(1, Glob->ResolEcran);
        }else
        {
            Corr_Vert_Sans_Tableau:
            if( Glob->bConception)
            {
                ptHtG.y = m_PointHtG.y + BandeOwner->Top;
                ptBsD.y = m_PointBsD.y + BandeBs->Top;
            }
            else
            {
                if( BandeRef == BandeOwner)
                    ptHtG.y = m_PointHtG.y + rMargeBandeRef.Top;
                else
                    ptHtG.y = rMargeBandeRef.Top;

                if( m_CaracCp & car_Graphic)
                {
                    if( BandeRef != BandeBs)
                        ptBsD.y = rMargeBandeRef.Bottom ;
                    else
                        ptBsD.y = m_PointBsD.y + rMargeBandeRef.Top;
                }else
                    ptBsD.y = m_PointBsD.y + rMargeBandeRef.Top;
            }
        }
        if( (m_CaracCp & car_Graphic) && ( BandeRef == BandeBs))
        {
            ptBsD.y = max( ptBsD.y, TCoordonnee::Pix( max(0,AspectY( PenWidthBas).PixelsEcran-1) + rMargeBandeRef.Top.PixelsEcran, Glob->ResolEcran));
            ptBsD.y = min( ptBsD.y, rMargeBandeRef.Bottom);
        }
    }


    if( m_GetTrueCoorHtG.x.Twips != -1 && (LARGEUR_SANS_MARGE_GAUCHE == m_LargTrueCoor))
    {
        ptHtG.x = m_GetTrueCoorHtG.x;
        ptBsD.x = m_GetTrueCoorBsD.x;
    }else if(m_CaracCp & car_LargeurColonne)
    {
        m_DecalInterneGauche = 0;
        m_DecalInterneDroite = 0;
        if( !m_NomChpHorzAssocie.IsEmpty() && m_NumColonne != -1)
        {
            int nIndex = EtatOwner->LstCpTableau?EtatOwner->LstCpTableau->IndexOf(m_NomChpHorzAssocie):0;
            if( nIndex != -1)
            {
                TCpTableau *CpTab;
                if( EtatOwner->LstCpTableau)
                    CpTab = dynamic_cast<TCpTableau*>(EtatOwner->LstCpTableau->Objects[nIndex]);
                else{
                    TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpHorzAssocie);
                    if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpHorzAssocie);
                    CpTab = dynamic_cast<TCpTableau*>(Cp);
                }
                if( CpTab)
                {
                    int nColDeb, nColFin;
                    bool bChampEnDehorsDuTableau = false;
                    TCoorRect RcTab;
                    CpTab->GetTrueCoordonnees( RcTab, BandeADessiner);

                    nColDeb = nColFin = LOBYTE(m_NumColonne);
                    nColFin = min( nColFin + HIBYTE(m_NumColonne), CpTab->ColonnesCount-1);
                    if( CpTab->BandeOwner == BandeOwner)
                    {
                        bChampEnDehorsDuTableau = ptBsD.y < RcTab.Top;
                        if( !bChampEnDehorsDuTableau && CpTab->BandeBs == BandeOwner)
                           bChampEnDehorsDuTableau = (ptHtG.y > RcTab.Bottom);
                    }
                    else if( CpTab->BandeBs == BandeOwner)
                        bChampEnDehorsDuTableau = (ptHtG.y > RcTab.Bottom);
                    else
                        bChampEnDehorsDuTableau = EtatOwner->LstCpEnCours &&
                                                  (EtatOwner->LstCpEnCours->IndexOf(CpTab) == -1);

                    if( nColDeb == CpTab->ColonnesCount)
                    {
                        ptHtG.x = RcTab.Left;
                        ptBsD.x = RcTab.Right;
                        if( !bChampEnDehorsDuTableau)
                        {
                            ptHtG.x.PixelsX += AspectX( CpTab->PenWidthGauche).PixelsX;
                            ptBsD.x.PixelsX -= AspectX( CpTab->PenWidthDroit).PixelsX;
                        }
                    }else if( nColDeb < CpTab->ColonnesCount )
                    {
                        COLONNE *cDeb = CpTab->GetColonne( nColDeb);
                        while( !cDeb->Visible && (nColDeb < nColFin))
                        {
                            nColDeb++;
                            cDeb = CpTab->GetColonne( nColDeb);
                        }
                        if( cDeb->Visible)
                        {
                            COLONNE *cFin = CpTab->GetColonne( nColFin);
                            while( !cFin->Visible && (nColDeb < nColFin))
                            {
                                nColFin--;
                                cFin = CpTab->GetColonne( nColFin);
                            }
                            ptHtG.x = CpTab->GetGaucheColonne( nColDeb);
                            ptBsD.x = CpTab->GetDroiteColonne( nColFin);
                            if( Glob->ResolutionX != Glob->ResolEcran)
                            {
                                PushResolutionAndPutEcran();
                                m_DecalInterneGauche = ptHtG.x - CpTab->GetGaucheColonne( nColDeb, false);
                                m_DecalInterneDroite = ptBsD.x - CpTab->GetDroiteColonne( nColFin, false);
                                PopResolution();
                            }
                            if( bChampEnDehorsDuTableau)
                            {
                                ptHtG.x.PixelsX -= AspectX( nColDeb                        ? CpTab->PenWidthLine : CpTab->PenWidthGauche).PixelsX;
                                ptBsD.x.PixelsX += AspectX( (nColFin!=CpTab->ColonnesCount-1)? CpTab->PenWidthLine : CpTab->PenWidthDroit).PixelsX;
                            }
                        }else
                            *((bool*)&m_VisibleCalc) = false;
                    }else goto Corr_Sans_Tableau;
                }else goto Corr_Sans_Tableau;
            }else goto Corr_Sans_Tableau;
        }
    }else if( m_CaracCp & car_LargeurEtat)
    {
        ptHtG.x = LargBarreGauche + DocOwner->Marges.Left;
        ptBsD.x = EtatOwner->Largeur - DocOwner->Marges.Right;
    }else if( m_CaracCp & car_ColleGauche)
    {
        bool bRectifG = false;
        TCoordonnee G;
        if( !m_NomChpHorzAssocie.IsEmpty())
        {
            TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpHorzAssocie);
            if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpHorzAssocie);
            if( !dynamic_cast<TCpTableau*>(Cp) && !dynamic_cast<TCpChamp*>(Cp))  goto Corr_Sans_Tableau;
            if( !Cp->GetVisible()) return;
            G = Cp->Droit;
            bRectifG = true;
        }else G = LargBarreGauche + DocOwner->Marges.Left;

        ptHtG.x = G;
        ptBsD.x = ptHtG.x + Largeur;
        if( bRectifG)
        {
            ptHtG.x += TCoordonnee::Pixels2TwipsX( 1);
            ptBsD.x += TCoordonnee::Pixels2Twips( 1, Glob->ResolEcran);
        }
    }else if( m_CaracCp & car_ColleDroite)
    {
        bool bRectifD = false;
        TCoordonnee D;
        if( !m_NomChpHorzAssocie.IsEmpty())
        {
            TComposant *Cp = m_ListCpOwner->GetComposant( m_NomChpHorzAssocie);
            if( !Cp) Cp = EtatOwner->GetComposant( m_NomChpHorzAssocie);
            if( !dynamic_cast<TCpTableau*>(Cp) && !dynamic_cast<TCpChamp*>(Cp))  goto Corr_Sans_Tableau;
            if( !Cp->GetVisible()) return;
            D = Cp->Gauche;
            bRectifD = true;
        }else D = EtatOwner->Largeur - DocOwner->Marges.Right;
        ptBsD.x = D;
        ptHtG.x = ptBsD.x - Largeur;
        if( bRectifD)
        {
            ptBsD.x -= TCoordonnee::Pixels2TwipsX( 1);
            ptHtG.x -= TCoordonnee::Pixels2Twips( 1, Glob->ResolEcran);
        }
    }else
    {
        Corr_Sans_Tableau:
        TCoordonnee G = LargBarreGauche + DocOwner->Marges.Left;
        ptHtG.x = G + m_PointHtG.x;
        ptBsD.x = G + m_PointBsD.x;
    }
    }catch( EAbort &e){ throw;}
    CATCH_EXCEPTION( TAG( 1))

    m_bdDess                = BandeADessiner;
    m_bdHautTop             = bdRefTop;
    m_GetTrueCoorHtG        = ptHtG;
    m_GetTrueCoorBsD        = ptBsD;
    m_LargTrueCoor          = LARGEUR_SANS_MARGE_GAUCHE;
}
//---------------------------------------------------------------------------
TCoordonnee  __fastcall TComposant::GetLargeur()const   { return DroitReel - GaucheReel;};
TCoordonnee  __fastcall TComposant::GetHauteur()const
{
    if( m_CaracCp & car_Graphic)
        return TCoordonnee::Pixels2Twips( BandeBs->Top.PixelsR[Glob->ResolEcran] + BasReel.PixelsR[Glob->ResolEcran] - BandeOwner->Top.PixelsR[Glob->ResolEcran] - HautReel.PixelsR[Glob->ResolEcran], Glob->ResolEcran);
    else
        return BasReel - HautReel;
};
TCoordonnee  __fastcall TComposant::GetGauche()const    { TCoorRect Rc; GetTrueCoordonnees( Rc); return Rc.Left; };
TCoordonnee  __fastcall TComposant::GetHaut()const      { TCoorRect Rc; GetTrueCoordonnees( Rc); return Rc.Top- BandeOwner->Top;};
TCoordonnee  __fastcall TComposant::GetDroit()const     { TCoorRect Rc; GetTrueCoordonnees( Rc); return Rc.Right;};
TCoordonnee  __fastcall TComposant::GetBas()const       { TCoorRect Rc; GetTrueCoordonnees( Rc); return Rc.Bottom - BandeBs->Top;};
TCoordonnee  __fastcall TComposant::GetGaucheReel()const{ return DocOwner->Marges.Left + m_PointHtG.x; };
TCoordonnee  __fastcall TComposant::GetHautReel()const  { return /*BandeOwner->Top + */m_PointHtG.y;     };
TCoordonnee  __fastcall TComposant::GetDroitReel()const { return DocOwner->Marges.Left + m_PointBsD.x; };
TCoordonnee  __fastcall TComposant::GetBasReel()const   { return /*BandeBs->Top + */m_PointBsD.y;       };
TCoorRect __fastcall TComposant::GetTrueCoordonnees( TCoorRect &Rc, const TBande* BandeADessiner)const
{
    TCoorPoint ptHtG, ptBsD;
    GetTrueCoordonnees( ptHtG, ptBsD, BandeADessiner);
    Rc.Left   = ptHtG.x;
    Rc.Top    = ptHtG.y;
    Rc.Right  = ptBsD.x;
    Rc.Bottom = ptBsD.y;
    return Rc;
}
//---------------------------------------------------------------------------
HRGN __fastcall TComposant::GetRgnSel( )
{
    if( m_hSel)
    {
        ::_DeleteObject( TAGL, m_hSel);
        m_hSel = NULL;
    }
    if( !m_bSelected)
    {
        m_hSel = ::_CreateRectRgn( TAGL, 0,0,0,0);
        if( !m_hSel) AfficheLastErrorT("CreateRectRgn");
    }
    else
    {
        #define NB_RECT 8
        POINT pt[ NB_RECT];
        TCoorPoint  ptHtG, ptBsD;   GetTrueCoordonnees( ptHtG, ptBsD);

// dessin des carrés ds les coins
        pt[ 0/*sel_HautGauche*/  ].x = ptHtG.x.PixelsX - 2;
        pt[ 3/*sel_MilieuGauche*/].x = ptHtG.x.PixelsX - 2;
        pt[ 5/*sel_BasGauche*/   ].x = ptHtG.x.PixelsX - 2;

        pt[ 1/*sel_HautMilieu*/  ].x = ptHtG.x.PixelsX + (ptBsD.x.PixelsX - ptHtG.x.PixelsX)/2 - 2;
        pt[ 6/*sel_BasMilieu*/   ].x = ptHtG.x.PixelsX + (ptBsD.x.PixelsX - ptHtG.x.PixelsX)/2 - 2;

        pt[ 2/*sel_HautDroit*/   ].x = ptBsD.x.PixelsX - 2;
        pt[ 4/*sel_MilieuDroit*/ ].x = ptBsD.x.PixelsX - 2;
        pt[ 7/*sel_BasDroit*/    ].x = ptBsD.x.PixelsX - 2;

        pt[ 0/*sel_HautGauche*/  ].y = ptHtG.y.PixelsY - 2;
        pt[ 1/*sel_HautMilieu*/  ].y = ptHtG.y.PixelsY - 2;
        pt[ 2/*sel_HautDroit*/   ].y = ptHtG.y.PixelsY - 2;

        pt[ 3/*sel_MilieuGauche*/].y = ptHtG.y.PixelsY + (ptBsD.y.PixelsY - ptHtG.y.PixelsY)/2 - 2;
        pt[ 4/*sel_MilieuDroit*/ ].y = ptHtG.y.PixelsY + (ptBsD.y.PixelsY - ptHtG.y.PixelsY)/2 - 2;

        pt[ 5/*sel_BasGauche*/   ].y = ptBsD.y.PixelsY - 2;
        pt[ 6/*sel_BasMilieu*/   ].y = ptBsD.y.PixelsY - 2;
        pt[ 7/*sel_BasDroit*/    ].y = ptBsD.y.PixelsY - 2;

        m_hSel = ::_CreateRectRgn( TAGL, 0, 0, 0, 0);

        HRGN hRgnCarre = ::_CreateRectRgn( TAGL, 0, 0, 0, 0);
        for( int i = 0; i < 8; i++)
        {
            ::_SetRectRgn( TAGL, hRgnCarre, pt[ i].x, pt[ i].y, pt[ i].x + 5, pt[ i].y + 5);
            ::_CombineRgn( TAGL, m_hSel, m_hSel, hRgnCarre, RGN_OR);
        }
        ::_DeleteObject( TAGL, hRgnCarre);

// Rectangle autour du contrôle
        #define LEN_TRAIT 15
        #define PAS       23
        HRGN hRgnRcArround  = ::_CreateRectRgn( TAGL, ptHtG.x.PixelsX, ptHtG.y.PixelsY, ptBsD.x.PixelsX+Glob->nRectifPourDessin, ptBsD.y.PixelsY+Glob->nRectifPourDessin);
        HRGN hRgnTmp        = ::_CreateRectRgn( TAGL, ptHtG.x.PixelsX+Glob->nRectifPourDessin, ptHtG.y.PixelsY+Glob->nRectifPourDessin, ptBsD.x.PixelsX, ptBsD.y.PixelsY);
        ::_CombineRgn( TAGL, hRgnRcArround, hRgnRcArround, hRgnTmp, RGN_DIFF);
        for( int x = ptHtG.x.PixelsX, y = ptHtG.y.PixelsY, pasX = PAS, pasY = 0;;)
        {
            if( pasX > 0)
            {
                if( (x + PAS) > ptBsD.x.PixelsX)
                {
                    pasX = 0;
                    pasY = PAS;
                    y = ptHtG.y.PixelsY - (ptBsD.x.PixelsX - x);
                    x = ptBsD.x.PixelsX;
                }
                else
                {
                    ::_SetRectRgn( TAGL, hRgnTmp, x + LEN_TRAIT, y, x + PAS, y + Glob->nRectifPourDessin);
                    x += pasX;
                }
            }
            else if( pasY > 0)
            {
                if( (y  + PAS) > ptBsD.y.PixelsY)
                {
                    pasX = -PAS;
                    pasY = 0;
                    x = ptBsD.x.PixelsX + (ptBsD.y.PixelsY - y);
                    y = ptBsD.y.PixelsY;
                }
                else
                {
                    ::_SetRectRgn( TAGL, hRgnTmp, x, y + LEN_TRAIT, x + Glob->nRectifPourDessin, y + PAS);
                    y += pasY;
                }
            }
            else if( pasX < 0)
            {
                if( (x - PAS) < ptHtG.x.PixelsX)
                {
                    pasX = 0;
                    pasY = -PAS;
                    y = ptBsD.y.PixelsY + (x - ptHtG.x.PixelsX);
                    x = ptHtG.x.PixelsX;
                }
                else
                {
                    ::_SetRectRgn( TAGL, hRgnTmp, x - LEN_TRAIT, y, x - PAS, y + Glob->nRectifPourDessin);
                    x += pasX;
                }
            }
            else if( pasY < 0)
            {
                if( (y - PAS)< ptHtG.y.PixelsY)
                    break;
                else
                {
                    ::_SetRectRgn( TAGL, hRgnTmp, x , y - LEN_TRAIT, x + Glob->nRectifPourDessin, y - PAS);
                    y += pasY;
                }
            }
            ::_CombineRgn( TAGL, hRgnRcArround, hRgnRcArround, hRgnTmp, RGN_DIFF);
        }
        ::_DeleteObject( TAGL, hRgnTmp);

        ::_CombineRgn( TAGL, m_hSel, m_hSel, hRgnRcArround, RGN_OR);

        ::_DeleteObject( TAGL, hRgnRcArround);
        ASSERT( m_hSel);
    }
    ASSERT( m_hSel);
    return m_hSel;
}

//---------------------------------------------------------------------------
void __fastcall TComposant::Invalidate( const TCoordonnee *Left, const TCoordonnee *Top, const TCoordonnee *Right, const TCoordonnee *Bottom)
{
    TCoorRect Rc;
    m_GetTrueCoorHtG.x.Twips = -1;
    m_GetTrueCoorHtG.y.Twips = -1;
    m_VisibleCalc = true;
    m_DansUneColonneViree = -1;
    if( Glob->bConception)
    {
        GetTrueCoordonnees( Rc);
        if( Left)    Rc.Left = *Left;
        if( Top)     Rc.Top  = *Top;
        if( Right)   Rc.Right = *Right;
        if( Bottom)  Rc.Bottom  = *Bottom;
        InvalidateR( Rc);
        if( m_bSelected)
            InvalidateSelect( );
    }
}

void __fastcall TComposant::InvalidateSelect( )
{
    _Invalidate( GetRgnSel());
}
//---------------------------------------------------------------------------

void __fastcall TComposant::DrawSelect( TColor cl)
{
    if( !m_bSelected)
    {
            // Invalide les carrés de selection
        InvalidateSelect();
   //     EtatOwner->Draw( );
        return;
    }

    TCanvas *c = IsCanvasSupport();
    if( c)
    {
        c->Brush->Style   = bsSolid;
        c->Brush->Color   = cl;
        // dessin des carrés ds les coins
        HRGN hRgn = GetRgnSel();
        ::_FillRgn( TAGL, c->Handle, hRgn, c->Brush->Handle);
    }
}

void __fastcall TComposant::CouleurDraw()
{
    TCanvas *c = IsCanvasSupport();
    if( c)
    {
        c->Pen->Color   = m_PenColor;
        c->Pen->Style   = m_PenStyle;
        c->Brush->Color = m_BrushColor;
        c->Brush->Style = m_BrushStyle;
    }
}
//---------------------------------------------------------------------------

void __fastcall TComposant::CouleurEfface()
{
    TCanvas *c = IsCanvasSupport();
    if( c)
    {
        c->Pen->Style   = m_PenStyle;
        c->Pen->Color   = (m_PenColor  != clNone)?clWindow:clNone;
        c->Brush->Style = m_BrushStyle;
        c->Brush->Color = (m_BrushColor != clNone)?clWindow:clNone;
    }
}
//---------------------------------------------------------------------------
void __fastcall TComposant::SetLstOwner( TListOfComposants *LstCp)
{
    m_ListCpOwner->Extract( this);
    LstCp->Add( this);
    m_ListCpOwner = LstCp;
}
//---------------------------------------------------------------------------
void __fastcall TComposant::SetCaracCp( Carac_Composant CaracCp)
{
    if( CaracCp == m_CaracCp) return;
    if( CaracCp & car_MskHauteur)
    {
        m_CaracCp = (Carac_Composant)( (m_CaracCp & ~car_MskHauteur)
                                      |(CaracCp & car_MskHauteur));
    }
    if( CaracCp & car_MskLargeur)
    {
        m_CaracCp = (Carac_Composant)( (m_CaracCp & ~car_MskLargeur)
                                      |(CaracCp & car_MskLargeur));
    }
    m_GetTrueCoorHtG.y.Twips = -1;
    m_GetTrueCoorHtG.x.Twips = -1;
    Modifie();
}
//---------------------------------------------------------------------------
void __fastcall TComposant::SetGauche( const TCoordonnee &Left)
{ _SetBounds( Left,   Haut, Droit, Bas);}
void __fastcall TComposant::SetHaut( const TCoordonnee &Top)
{ _SetBounds( Gauche, Top,  Droit, Bas);}
void __fastcall TComposant::SetDroit( const TCoordonnee &Right)
{ _SetBounds( Gauche, Haut, Right, Bas);}
void __fastcall TComposant::SetBas( const TCoordonnee &Bottom)
{ _SetBounds( Gauche, Haut, Droit, Bottom);}
void __fastcall TComposant::SetPointHtG( const TCoordonnee &Left, const TCoordonnee &Top)
{ _SetBounds( Left,   Top,  Droit, Bas);}
void __fastcall TComposant::SetPointHtD( const TCoordonnee &Right, const TCoordonnee &Top)
{ _SetBounds( Gauche, Top,  Right, Bas);}
void __fastcall TComposant::SetPointBsG( const TCoordonnee &Left, const TCoordonnee &Bottom)
{ _SetBounds( Left,   Haut, Droit, Bottom);}
void __fastcall TComposant::SetPointBsD( const TCoordonnee &Right, const TCoordonnee &Bottom)
{ _SetBounds( Gauche, Haut, Right, Bottom);}
void __fastcall TComposant::SetBounds(  const TCoordonnee &Left, const TCoordonnee &Top, const TCoordonnee &Right, const TCoordonnee &Bottom)
{ _SetBounds( Left, Top, Right, Bottom); }

void __fastcall TComposant::SetLargeur( const TCoordonnee &l)
{
    TCoorRect rLim; GetLimites(rLim);
    TCoordonnee vL = min( l, rLim.Right - Gauche);
    Droit = Gauche + vL;
}
void __fastcall TComposant::SetHauteur( const TCoordonnee &h)
{
    TCoorRect rLim; GetLimites(rLim);
    TCoordonnee vH = min( h, rLim.Bottom - Haut);
    Bas = BandeOwner->Top + Haut + vH - BandeBs->Top;
}
void __fastcall TComposant::_SetBounds( const TCoordonnee &L, const TCoordonnee &T, const TCoordonnee &R, const TCoordonnee &B)
{
    TCoordonnee Left, Top, Right, Bottom;
    if( Editing) return;
    if( L > R) { Left = R; Right = L;}
    else       { Left = L; Right = R;}
    if( !(m_CaracCp & car_Graphic))
    {
        if( T > B) { Top = B; Bottom = T;}
        else       { Top = T; Bottom = B;}
    }else{
        Top = T; Bottom = B;
    }

    TCoorPoint  OldPtHtG, OldPtBsD;
    TCoorRect rc;
    GetTrueCoordonnees( OldPtHtG, OldPtBsD);
        // On invalide l'ancienne selection
    if( m_bSelected) InvalidateSelect();

    BandeOwner->GetLimites( rc);
    rc.Top = 0; rc.Bottom = BandeOwner->Hauteur;

    if( (m_CaracCp & car_Graphic) && !(m_CaracCp & (car_HauteurBande|car_HauteurLigne)))
    {
        if( (Top < rc.Top) || (Top > rc.Bottom) )
        {
            Top += BandeOwner->Top;
            TBande* b = EtatOwner->GetBande( max( Top, TCoordonnee( 0)));
            while( !b)
            {
                Top.PixelsY++;
                b = EtatOwner->GetBande( max( Top, TCoordonnee( 0)));
            }
            SetLstOwner( b->LstComposants);
            Top -= BandeOwner->Top;
//            _SetBounds( L, T, R, B);
        }

        BandeBs->GetLimites( rc);
        rc.Top = 0; rc.Bottom = BandeBs->Hauteur;  rc.Bottom.PixelsY -= HAUTEUR_ENTRE_BANDES;
        if( (Bottom < rc.Top) || (Bottom >= rc.Bottom))
        { // changement de bande pour le bas du composant
            TBande *b = EtatOwner->GetBande( min( BandeBs->Top + Bottom, EtatOwner->Hauteur));
            int ToursDeBoucle = HAUTEUR_ENTRE_BANDES;
            while( !b)
            {
                Bottom.PixelsY += (((m_PointBsD.y>Bottom)? -1:1) * ((ToursDeBoucle<0)?-1:1));
                b = EtatOwner->GetBande( min( BandeBs->Top + Bottom, EtatOwner->Hauteur));
                ToursDeBoucle--;
            }
            Bottom += BandeBs->Top;
            m_eTypeBandeBs = b->Type;
            m_wNiveauBs    = b->Niveau;
            Bottom -= BandeBs->Top;
            if( (BandeOwner->Type != e_Pied) && (m_eTypeBandeBs == e_Pied) && (m_wNiveauBs==0))
            {
                if( BandeOwner->OwnerDocument)
                    DocOwner->CpEndsInPied |= true;
                else
                    EtatOwner->CpEndsInPied |= true;
            }
        }
    }else
    {
        if( Top < rc.Top)         { Top = rc.Top;    /*Top.Pixels++;*/}
        else if (Top > rc.Bottom) { Top = rc.Bottom; Top.PixelsY--;}

        if( Top > Bottom) { TCoordonnee c = Top; Top = Bottom; Bottom = c;}
    }

        // On initialise les nouvelles coordonnees
    bool Change = false;

    if( m_PointHtG.x != Left - LargBarreGauche - DocOwner->Marges.Left){
        m_PointHtG.x = Left - LargBarreGauche - DocOwner->Marges.Left;
        Change = true;
    }
    if( m_PointHtG.y != Top /*-   BandeOwner->Top*/){
        m_PointHtG.y = Top /*-   BandeOwner->Top*/;
        Change = true;
    }
    if( m_PointBsD.x != Right - LargBarreGauche - DocOwner->Marges.Left){
        m_PointBsD.x = Right - LargBarreGauche - DocOwner->Marges.Left;
        Change = true;
    }
    if( m_PointBsD.y != Bottom /*- BandeBs->Top*/) {
        m_PointBsD.y = Bottom /*- BandeBs->Top*/;
        Change = true;
    }

    if( Change)
    {
        TCoorPoint NewPtHtG, NewPtBsD;
        m_GetTrueCoorHtG.x.Twips = -1;
        m_GetTrueCoorHtG.y.Twips = -1;
        GetTrueCoordonnees( NewPtHtG, NewPtBsD);

        TCoorRect r;
        // On invalide la nouvelle selection
        if( m_bSelected) InvalidateSelect();

        _Invalidate( OldPtHtG.x, OldPtHtG.y, OldPtBsD.x, OldPtBsD.y);
        Invalidate( );

        if(dynamic_cast<TCpTableau*>(this))
        {
            dynamic_cast<TCpTableau*>(this)->Nettoie();
            EtatOwner->InvalideComposantsAttacheA(dynamic_cast<TCpTableau*>(this)->Nom);
        }
        if(dynamic_cast<TCpChamp*>(this))
            EtatOwner->InvalideComposantsAttacheA(dynamic_cast<TCpChamp*>(this)->Nom);
        Modifie();
    }
}
//---------------------------------------------------------------------------
TCoorRect& __fastcall TComposant::GetLimites( TCoorRect &r)const
{
    BandeOwner->GetMarges( r);
    if( m_CaracCp & car_Graphic)
    {
        TCoorRect MargeBd;
        EtatOwner->LstBandes->FirstBande()->GetMarges( MargeBd);
        r.Top = MargeBd.Top;
        EtatOwner->LstBandes->LastBande()->GetMarges( MargeBd);
        r.Bottom = MargeBd.Bottom;
    }

    return r;
}
//---------------------------------------------------------------------------
void __fastcall TComposant::SetSelected( bool b)
{
    if( m_bSelected)
        InvalidateSelect();
    m_bSelected = b;
    if( m_bSelected)
        InvalidateSelect();
}
//---------------------------------------------------------------------------
void __fastcall TComposant::SetStyle( const AnsiString &s)
{
  if( s != m_Style)
  {
    m_Style = s;
    if( m_Style.IsEmpty())
    {
      BrushColor = DocOwner->ColorDefaut;
      BrushStyle = bsClear;
      TCpTexte *cpT = dynamic_cast<TCpTexte*>(this);
      if( cpT)
      {
        cpT->Font = DocOwner->FontDefaut;
        Text_Presentation tp = Tx_HGauche;
        if( (cpT->Format == tf_Monetaire) || (cpT->Format == tf_Numerique))
            tp = Tx_HDroite;
        cpT->Presentation = (Text_Presentation)((cpT->Presentation & ~(Tx_HGauche | Tx_HCentre | Tx_HDroite) ) | tp);
      }
    }else if( !Glob->bConception)
        AppliqueStyle();
    Modifie();
  }
}
//---------------------------------------------------------------------------

void __fastcall TComposant::Nettoie( )
{
    m_GetTrueCoorHtG.x.Twips = -1;
    m_GetTrueCoorHtG.y.Twips = -1;
    m_GetTrueCoorBsD.x.Twips = -1;
    m_GetTrueCoorBsD.y.Twips = -1;
}
bool __fastcall TComposant::GetStyle( EICStyle *&Style)
{
    if( !m_Style.IsEmpty())
    {
        int index = DocOwner->Styles->IndexOf( m_Style);
        if( index != -1)
        {
            Style = (EICStyle *)DocOwner->Styles->Objects[index];
            return true;
        }
    }
    return false;
}
void __fastcall TComposant::AppliqueStyle( EICStyle *pStyle)
{
    EICStyle *Style = pStyle;                    
    if( Style || GetStyle( Style))
    {
        if( Style->BrushColor != Nocl)                     BrushColor = Style->BrushColor;
        if( Style->BrushStyle != Nobs && !ForceBrushStyle) BrushStyle = Style->BrushStyle;
    }
}
//---------------------------------------------------------------------------
bool __fastcall TComposant::IsComposantAttacheA( const AnsiString &ChpAttache)
{
    if(    (  ChpAttache.IsEmpty()              && (m_CaracCp & car_LargeurEtat                                        ))
        || ( (ChpAttache == BandeHt->Titre)     && (m_CaracCp & car_HauteurBande                                       ))
        || ( (ChpAttache == m_NomChpHorzAssocie)&& (m_CaracCp & (car_LargeurColonne | car_ColleGauche | car_ColleDroite)))
        || ( (ChpAttache == m_NomChpVertAssocie)&& (m_CaracCp & (car_HauteurLigne   | car_ColleHaut   | car_ColleBas   ))))
    {
        return true;
//        Invalidate();
//        Nettoie();
//        Invalidate();
    }
    return false;
}

void __fastcall TComposant::ControleApresSuppression( const TBande *b)
{
    if( (m_eTypeBandeBs == b->Type) &&
        (m_wNiveauBs == b->Niveau) )
    {
        if( (m_eTypeBandeBs == e_DebutColonne) || (m_eTypeBandeBs == e_FinColonne))
        {
            TListOfBandes *Lst = EtatOwner->LstBandes;
            do{
                if( b->LstBandesOwner != Lst)
                {
                    TBande *bAutre = Lst->SearchBande( m_eTypeBandeBs);
                    if( bAutre)
                    {
                        m_wNiveauBs = bAutre->Niveau;
                        return;
                    }
                }
                Lst = Lst->SearchBande( e_Principal)->LstBandes;
            }while( Lst);
        }else{
            Invalidate();
            m_eTypeBandeBs = BandeOwner->Type;
            m_wNiveauBs = BandeOwner->Niveau;
            m_PointBsD.y.PixelsY = BandeOwner->Hauteur.PixelsY - HAUTEUR_ENTRE_BANDES-Glob->nRectifPourDessin;
        }

    }
}
//---------------------------------------------------------------------------

void __fastcall TComposant::ClipAndCombineWith( HRGN hGeneral, const TBande* BandeADessiner)
{
    if( Glob->bConception && hGeneral)
    {
        TCanvas *canvas = IsCanvasSupport();
        if( canvas)
        {
            TCoorRect rc; TRect r;
            GetTrueCoordonnees( rc, BandeADessiner?BandeADessiner:BandeOwner);
            r = rc.RectPixels;
            if( IsPrinting()) Glob->EICPrinter->RectifieCoordonnees(r);
            ::_SetRectRgn( TAGL, Glob->hRgnTmp1, r.Left,r.Top,r.Right+1,r.Bottom+1);
            if( hGeneral)
            {
                if( m_bSelected)
                    ::_CombineRgn( TAGL, Glob->hRgnTmp1, Glob->hRgnTmp1, GetRgnSel(), RGN_OR);
                ::_CombineRgn( TAGL, Glob->hRgnTmp1, Glob->hRgnTmp1, hGeneral, RGN_AND);
            }
            ::_SelectClipRgn( TAGL, canvas->Handle, Glob->hRgnTmp1);
        }
    }
}
//---------------------------------------------------------------------------
TComposant* __fastcall  TComposant::GetPrecedentSuivant( bool bPrec)const
{
    return m_ListCpOwner->GetPrecedentSuivant( bPrec, this);
}
TComposant* __fastcall  TComposant::GetChampEnDessous( )const
{
    return m_ListCpOwner->GetChampEnDessous( this);
}


//---------------------------------------------------------------------------
//----------------              RECTANGLE             -----------------------
//---------------------------------------------------------------------------

__fastcall TCpRectangle::TCpRectangle( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                        :TComposant( ListCp, X, Y, CaracCp)
{
    m_RayonCourbure.PixelsX = 0;
}
//---------------------------------------------------------------------------

__fastcall TCpRectangle::TCpRectangle( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                        :TComposant( ListCp, f, CaracCp)
{
    m_RayonCourbure.Lit( f);
}
//---------------------------------------------------------------------------

void __fastcall TCpRectangle::Enregistre( TFlux *f) const
{
    TComposant::Enregistre( f);
    m_RayonCourbure.Enregistre( f);
}

//---------------------------------------------------------------------------

void __fastcall TCpRectangle::Dessine( const TBande* BandeADessiner)
{
    TCoorRect CoorRc;
    GetTrueCoordonnees( CoorRc, BandeADessiner);
    if( IsRectInvalideInClip( CoorRc.RectPixels))
    {
        bool bDessineHaut = (BandeADessiner==BandeOwner),
             bDessineBas = (BandeADessiner==BandeBs);
        TComposant::CouleurDraw();
        DrawRectangle( DocOwner->Support, CoorRc.RectPixels, m_RayonCourbure.PixelsX,
                       m_BrushColor, m_BrushStyle, PenColor, m_PenStyle,
                       m_PenWidthGauche, bDessineHaut?m_PenWidthHaut:0,
                       m_PenWidthDroit, bDessineBas?m_PenWidthBas:0,
                       m_MoitieGauche, m_MoitieDroit);
        TComposant::Dessine( BandeADessiner);
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpRectangle::InvalidateR( const TCoorRect &Rc)
{
    TCoorRect RcTrue;
    GetTrueCoordonnees( RcTrue);
    if( (BrushStyle != bsSolid) && (BrushStyle != bsClear))
    {
        _Invalidate( min( RcTrue.Left,   Rc.Left  ),
                         min( RcTrue.Top,    Rc.Top   ),
                         max( RcTrue.Right,  Rc.Right ),
                         max( RcTrue.Bottom, Rc.Bottom));
    }
    else
        _Invalidate( Rc);
}

//---------------------------------------------------------------------------
//----------------               ELLIPSE              -----------------------
//---------------------------------------------------------------------------

__fastcall TCpEllipse::TCpEllipse( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                      :TComposant( ListCp, X, Y, CaracCp)
{
}
//---------------------------------------------------------------------------

__fastcall TCpEllipse::TCpEllipse( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                      :TComposant( ListCp, f, CaracCp)
{
}
//---------------------------------------------------------------------------

void __fastcall TCpEllipse::Dessine( const TBande* BandeADessiner)
{
    TCoorRect CoorRc;
    GetTrueCoordonnees( CoorRc, BandeADessiner);
    if( IsRectInvalideInClip( CoorRc.RectPixels))
    {
        TComposant::CouleurDraw();
        DrawEllipse( DocOwner->Support, CoorRc.RectPixels,
                     m_BrushColor, m_BrushStyle, PenColor, m_PenStyle, m_PenWidthGauche);
        TComposant::Dessine( BandeADessiner);
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpEllipse::InvalidateR( const TCoorRect &Rc)
{
    TCoorRect RcTrue;
    GetTrueCoordonnees( RcTrue);
    _Invalidate( min( RcTrue.Left,   Rc.Left  ),
                     min( RcTrue.Top,    Rc.Top   ),
                     max( RcTrue.Right,  Rc.Right ),
                     max( RcTrue.Bottom, Rc.Bottom));
}



//---------------------------------------------------------------------------
//----------------                TEXTE               -----------------------
//---------------------------------------------------------------------------
#include <typeinfo.h>
TObject*  __fastcall TCpTexte::GetpvFormat( )const
{
    if( !m_pvFormat)
    {  // traitement des valeurs par défaut du dossier
    #if tf_Max != 6
        #error "Format non reconnu"
    #endif
        switch( m_Format)
        {
            case tf_Numerique : return DocOwner->FormatNumDefaut;
            case tf_Monetaire : return EtatOwner->FormatCurDefaut? EtatOwner->FormatCurDefaut : DocOwner->FormatCurDefaut;
        }
    }else if( (m_Format == tf_Monetaire) && ((EICCurrencyFmt*)m_pvFormat)->ZeroSignificatif && EtatOwner->ForcerMonetaireSaufZeroSignificatif)
    {
        bool b = ((EICCurrencyFmt*)m_pvFormat)->ZeroSignificatif;
        ((EICCurrencyFmt*)m_pvFormat)->Assign( *(EtatOwner->FormatCurDefaut? EtatOwner->FormatCurDefaut : DocOwner->FormatCurDefaut));
        ((EICCurrencyFmt*)m_pvFormat)->ZeroSignificatif = b;
    }
    return m_pvFormat;
}

void   __fastcall TCpTexte::DetruitpvFormat( )
{
try{
#if tf_Max != 6
    #error "Format non reconnu"
#endif
#if bf_Max != 5
    #error "Format non reconnu"
#endif
  // Libération de la mémoire
    EICAnsiString  *as = NULL;
    EICCurrencyFmt *cf = NULL;
    EICNumberFmt   *nf = NULL;
    if( ((Bool_Format)m_pvFormat != bf_CaseACocher) &&
        ((Bool_Format)m_pvFormat != bf_ON) &&
        ((Bool_Format)m_pvFormat != bf_OuiNon) &&
        ((Bool_Format)m_pvFormat != bf_VF) &&
        ((Bool_Format)m_pvFormat != bf_VraiFaux)&&
        ((Bool_Format)m_pvFormat != bf_Croix) )
    {
        as = dynamic_cast<EICAnsiString*>(m_pvFormat);
        cf = dynamic_cast<EICCurrencyFmt*>(m_pvFormat);
        nf = cf? NULL : dynamic_cast<EICNumberFmt*>(m_pvFormat);
        if( as)  delete as;
        if( nf)  delete nf;
        if( cf && (cf!= EtatOwner->FormatCurDefaut))  delete cf;
    }
    m_pvFormat = NULL;
}CATCH_EXCEPTION(TAGL)
}

void   __fastcall TCpTexte::SetpvFormat( TObject* pv)
{
#if tf_Max != 6
    #error "Format non reconnu"
#endif
    TObject *Ob = NULL;
    if( !IsBadReadPtr(pv, sizeof( TObject)))
        Ob = dynamic_cast<TObject*>(pv) ;
    bool Change = false;
    if( Ob)
    {
        TObject *mOb = dynamic_cast<TObject*>(m_pvFormat);
        if( !mOb || (AnsiString( pv->ClassName()) != AnsiString( mOb->ClassName())))
        {
            Change = true;
        }else {
            EICAnsiString  *as = dynamic_cast<EICAnsiString*>(mOb);
            EICCurrencyFmt *cf = dynamic_cast<EICCurrencyFmt*>(mOb);
            EICNumberFmt   *nf = cf? NULL : dynamic_cast<EICNumberFmt*>(mOb);
            if(as)
            {
                EICAnsiString  *o = dynamic_cast<EICAnsiString*>(Ob);
                Change = !o || (as->Text != o->Text);
            }
            else if(cf) 
            {
                EICCurrencyFmt  *o = dynamic_cast<EICCurrencyFmt*>(Ob);
                Change = !o || (*cf != *o);
            }
            else if(nf)
            {
                EICNumberFmt  *o = dynamic_cast<EICNumberFmt*>(Ob);
                Change = !o || (*nf != *o);
            }
        }
    }else{
        if( pv != m_pvFormat)
        {
            Change = true;
        }
    }
    if( Change)
    {
        DetruitpvFormat();
        m_pvFormat = pv;
        Modifie();
    }
};

__fastcall TCpTexte::~TCpTexte( )
{
try{
    if( m_Font)      delete m_Font;
    if (m_LstTexte)  delete m_LstTexte;
    DetruitpvFormat();
}CATCH_EXCEPTION(TAGL)
}
//---------------------------------------------------------------------------

__fastcall TCpTexte::TCpTexte( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                    :TCpRectangle( ListCp, X, Y, CaracCp)
{
    byte nNbLangues;
    try{

        m_ed              = NULL;
        m_pvFormat        = NULL;
        m_Font            = NULL;
        m_FontCommentaire = NULL;
        m_Commentaire     = EmptyStr;
        m_fPresentationCommentaire   = (Text_Presentation)(Tx_HGauche | Tx_VHaut);
        m_fPresentation   = (Text_Presentation)(Tx_HGauche | Tx_VHaut);
        m_Orientation     = 0;
        m_Format          = tf_Normal;
        m_nLastCharPrint  = -1;
        m_LstTexte        = new TStringList();
        m_IdMiseEnForme   = 0;
        nNbLangues = /*(EtatOwner && EtatOwner->Ole)? 1 : */DocOwner->NbLangues;
        for( byte i = 0; i < nNbLangues; i++)
        {
            m_LstTexte->Add( EmptyStr);
        }
        m_Retrait = 0;
        m_EspaceTexte = 0;
    }CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------
__fastcall TCpTexte::TCpTexte( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                    :TCpRectangle( ListCp, f, CaracCp)
{
    try{
        m_pvFormat       = NULL;
        m_ed             = NULL;
        m_nLastCharPrint = -1;
        m_IdMiseEnForme  = 0;
        m_LstTexte       = new TStringList();
        m_FontCommentaire = NULL;
        m_Commentaire     = EmptyStr;
        m_fPresentationCommentaire = (Text_Presentation)(Tx_HGauche | Tx_VHaut);

        if( f->FileVersion >= FILE_VERSION( 1, 12))
        {
            byte nNbLangues = /*(EtatOwner && EtatOwner->Ole)? 1 : */DocOwner->NbLangues;
            AnsiString Txt;
            for( byte i = 0; i < nNbLangues; i++)
            {
                f->Lit( Txt);
                m_LstTexte->Add( Txt);
            }

            f->Lit( m_IdMiseEnForme);
        }else{
            AnsiString Txt;
            f->Lit( Txt);
            m_LstTexte->Add( Txt);
        }
        f->Lit( *((int*)&m_fPresentation));
        f->Lit( &m_Font);
        f->Lit( m_Orientation);
        f->Lit( m_SoulignePointille);
        f->Lit( *(int*)&m_Format);
    #if tf_Max != 6
        #error "Format non reconnu"
    #endif
        switch( m_Format)
        {
            case tf_Normal    : break;
            case tf_Adresse   : f->Lit( (int)m_pvFormat);                 break;
            case tf_Numerique : f->Lit( &((EICNumberFmt*)m_pvFormat));    break;
            case tf_Monetaire : f->Lit( &((EICCurrencyFmt*)m_pvFormat));  break;
            case tf_Booleen   : f->Lit( (int)m_pvFormat);                 break;
            case tf_Date      :
            case tf_CadreAdm  : { AnsiString s;
                                  f->Lit( s);
                                  m_pvFormat = new EICAnsiString( s);    }break;
        }
        if( m_fPresentation & Tx_Extensible)
        {
            Format = tf_Normal;
        }
        if( f->FileVersion >= FILE_VERSION( 1, 13))
            m_Retrait.Lit( f);

        if( f->FileVersion >= FILE_VERSION( 2, 11))
          {
          f->Lit( m_Commentaire);
          f->Lit( &m_FontCommentaire);
          }
        if( f->FileVersion >= FILE_VERSION( 2, 13))
          f->Lit( *((int*)&m_fPresentationCommentaire));

        if( f->FileVersion >= FILE_VERSION( 2, 14))
          m_EspaceTexte.Lit( f);

    }CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------

void __fastcall TCpTexte::Enregistre( TFlux *f)const
{
    TCpRectangle::Enregistre( f);
    for( int i = 0; i < m_LstTexte->Count; i++)
        f->Ecrit( m_LstTexte->Strings[ i]);
    byte nNbLangues = DocOwner->NbLangues;
    for( byte i = (byte)m_LstTexte->Count; i < nNbLangues; i++)
        f->Ecrit( EmptyStr);
    f->Ecrit( m_IdMiseEnForme);
    f->Ecrit( m_fPresentation);
    f->Ecrit( m_Font, DocOwner->FontDefaut);
    f->Ecrit( m_Orientation);
    f->Ecrit( m_SoulignePointille);
    f->Ecrit( (int)m_Format);
#if tf_Max != 6
    #error "Format non reconnu"
#endif
    switch( m_Format)
    {
        case tf_Normal    : break;
        case tf_Adresse   : f->Ecrit( (int)m_pvFormat);                                      break;
        case tf_Numerique : f->Ecrit( dynamic_cast<EICNumberFmt*>(m_pvFormat), DocOwner->FormatNumDefaut);   break;
        case tf_Monetaire : f->Ecrit( dynamic_cast<EICCurrencyFmt*>(m_pvFormat), DocOwner->FormatCurDefaut); break;
        case tf_Booleen   : f->Ecrit( (int)m_pvFormat);                                      break;
        case tf_Date      :
        case tf_CadreAdm  : f->Ecrit( ((EICAnsiString*)m_pvFormat)->Text);                           break;
    }
    m_Retrait.Enregistre( f);
    f->Ecrit( m_Commentaire);
    f->Ecrit( m_FontCommentaire, DocOwner->FontDefaut);
    f->Ecrit( m_fPresentationCommentaire);
    m_EspaceTexte.Enregistre( f);
}
//---------------------------------------------------------------------------

void   __fastcall TCpTexte::SetTexteLangue( byte IdLangue, int index, const AnsiString &pTexte)
{
    if( pTexte != m_LstTexte->Strings[IdLangue])
    {
        m_LstTexte->Strings[IdLangue] = pTexte;
        Modifie( );
    }
}
void   __fastcall TCpTexte::SetTexte( const AnsiString &pTexte)
{
    SetTexteLangue( DocOwner->Langue, 1, pTexte);
}
void       __fastcall TCpTexte::SetAllTextes( AnsiString &s)const
{
    m_LstTexte->CommaText = s;
    if( !m_LstTexte->Count)
        m_LstTexte->Add( "");
}
AnsiString __fastcall TCpTexte::GetAllTextes()const
{
    AnsiString t = m_LstTexte->CommaText;
    if( t.Length() && t[t.Length()]==',')
        t+= "\"\"";
    return t;
}
AnsiString __fastcall TCpTexte::GetTexteLangue( byte IdLangue, int index)const
{
    AnsiString s = m_LstTexte->Strings[IdLangue];
    if( index && s.IsEmpty())
        s=m_LstTexte->Strings[0];
    return s;
}
//---------------------------------------------------------------------------
void __fastcall TCpTexte::SupprimeLangue( byte IdLangue)
{
    m_LstTexte->Delete( IdLangue);
}

//---------------------------------------------------------------------------
void __fastcall TCpTexte::AjouteLangue( )
{
    m_LstTexte->Add( EmptyStr);
}
void   __fastcall TCpTexte::SetPresentation( Text_Presentation p)
{
    if( p != m_fPresentation)
    {
        bool bExtensible = Glob->bConception ? false : (m_fPresentation & Tx_Extensible);
        m_fPresentation = (Text_Presentation)(p | (bExtensible? Tx_Extensible : 0));
        if( m_fPresentation & Tx_Extensible)
            m_ListCpOwner->bTexteExtensible = true;
        Modifie( );
    }
}

void   __fastcall TCpTexte::SetPresentationCommentaire( Text_Presentation p)
{
    if( p != m_fPresentationCommentaire)
    {
    m_fPresentationCommentaire = p;
    Modifie( );
    }
}

//---------------------------------------------------------------------------
void __fastcall TCpTexte::GetTrueCoordonnees( TCoorPoint &ptHtG, TCoorPoint &ptBsD, const TBande* BandeADessiner)const
{
    inherited::GetTrueCoordonnees( ptHtG, ptBsD, BandeADessiner);
    if( !Glob->bConception               &&
        (m_fPresentation & Tx_Extensible)&&
        !(m_CaracCp & (car_HauteurBande | car_HauteurLigne | car_ColleBas)))
    {
        TCoordonnee HeightMin, HeightMax; bool b;
        WantedToChangeHeightOfBande( HeightMin, HeightMax, b);
        /*if(m_nLastCharPrint!=-1)
            ptHtG.y = BandeOwner->Top;
        TCoordonnee Bottom;
        TCoorRect   CoorRc;
        CoorRc.Left   = ptHtG.x + AspectX( m_PenWidthGauche) + DocOwner->MargeHorzCp;
        CoorRc.Top    = ptHtG.y + AspectY( m_PenWidthHaut) + DocOwner->MargeVertCp;
        CoorRc.Right  = ptBsD.x - AspectX( m_PenWidthDroit) - DocOwner->MargeHorzCp;
        CoorRc.Bottom = ptBsD.y - AspectY( m_PenWidthBas) - DocOwner->MargeVertCp;
        Glob->Rtf->InitContenu( CoorRc, Font, Texte,  m_fPresentation, m_nLastCharPrint);*/
        if( HeightMin > 0 && BandeADessiner)
        {
            TCoorRect rMargeBandeRef;
            BandeADessiner->GetMarges( rMargeBandeRef);
            ptBsD.y = min( rMargeBandeRef.Top + HeightMin, rMargeBandeRef.Bottom );
            if( b) ptHtG.y = rMargeBandeRef.Top;
        }
    }
}
//---------------------------------------------------------------------------
bool __fastcall TCpTexte::GetTrueCoordonneesInternes( bool bAvecDecalInterne, TCoorRect &CoorRc, const TBande* BandeADessiner)const
{
    GetTrueCoordonnees( CoorRc, BandeADessiner);

    TCoordonnee DecalInterneGauche = 0, DecalInterneDroite = 0;
    if(bAvecDecalInterne)
    {
         DecalInterneGauche = m_DecalInterneGauche;
         DecalInterneDroite = m_DecalInterneDroite;
    }

    CoorRc.Left   = CoorRc.Left + AspectX( m_PenWidthGauche) + DecalInterneGauche;
    CoorRc.Top    = CoorRc.Top + AspectY( m_PenWidthHaut);
    if( !(m_fPresentation & (Tx_HDroite | Tx_HJustify)) )
        CoorRc.Right  = CoorRc.Right - AspectX( m_PenWidthDroit) - DecalInterneDroite;
    CoorRc.Bottom = CoorRc.Bottom - AspectY( m_PenWidthBas) + m_DecalInterneBas;
    if( !(m_fPresentation & Tx_PasMargesInt))
    {
        CoorRc.Left   += DocOwner->MargeHorzCp;
        CoorRc.Top    += DocOwner->MargeVertCp;
        if( !(m_fPresentation & (Tx_HDroite | Tx_HJustify)) )
            CoorRc.Right  -= DocOwner->MargeHorzCp;
        CoorRc.Bottom -= DocOwner->MargeVertCp;
    }

    // Retrait du texte
    if( m_Retrait != 0)
    {
      if( m_fPresentation & (Tx_HDroite) )      CoorRc.Right -= m_Retrait;
      else if( m_fPresentation & (Tx_HGauche) ) CoorRc.Left  += m_Retrait;
    }

    bool bReturn = IsRectInvalideInClip( CoorRc.RECTPixels);

    if( (m_fPresentation & (Tx_HDroite | Tx_HJustify)) )
    {
        CoorRc.Right  = CoorRc.Right - AspectX( m_PenWidthDroit) - DecalInterneDroite;
        if( !(m_fPresentation & Tx_PasMargesInt))
            CoorRc.Right  -= DocOwner->MargeHorzCp;
    }
    if( CoorRc.Left > CoorRc.Right)
      return false;
    return bReturn;
}

//---------------------------------------------------------------------------
bool __fastcall TCpTexte::WantedToChangeHeightOfBande( TCoordonnee &HeightSouhaiteeMin, TCoordonnee &HeightSouhaiteeMax, bool &TiensIlEstEnCours)const
{
    HeightSouhaiteeMin.Twips = -1;
    HeightSouhaiteeMax.Twips = -1;
    AnsiString txt = GetTexte();
    if( !Glob->bConception && (m_fPresentation & Tx_Extensible) && !txt.IsEmpty() && GetVisible())
    {
        bool        bReturn  = false;
//        TCoordonnee LargTrueCoorAv = m_LargTrueCoor; TCoorRect   CoorRc2;
        TCoorRect   CoorRc;      TCoorPoint ptHtG, ptBsD;
//        on prend les coordonnées du cp comme si il etait pas extensible en coor ecran
        (const_cast<TCpTexte*>(this))->m_fPresentation = (Text_Presentation)(m_fPresentation & ~Tx_Extensible);
/*        if( PushResolutionAndPutEcran())
        {
          LargTrueCoorAv = m_LargTrueCoor;
          m_LargTrueCoor = LARGEUR_SANS_MARGE_GAUCHE; //evite le recalcul des coordonnées horizontales
        }
        GetTrueCoordonneesInternes( true, CoorRc);
        if( PopResolution())
        {
          m_LargTrueCoor = LargTrueCoorAv;
        }*/
        GetTrueCoordonneesInternes( true, CoorRc); // maintenant identique en coor ecran et dest
//        ASSERT( CoorRc2.Top == CoorRc.Top && CoorRc2.Bottom == CoorRc.Bottom && CoorRc2.Left == CoorRc.Left && CoorRc2.Right == CoorRc.Right);
        (const_cast<TCpTexte*>(this))->m_fPresentation = (Text_Presentation)(m_fPresentation | Tx_Extensible);

        if( CoorRc.Right.Twips - CoorRc.Left.Twips < 0)
            bReturn = false;
        else{
            TiensIlEstEnCours = (m_nLastCharPrint!=-1);
            if( TiensIlEstEnCours)
            {
                ptHtG.y = 0;
                ptBsD.y = 0;
            }
            TCoordonnee HauteurVoulue,
                        BasBande = BandeOwner->Top + BandeOwner->Hauteur;
            TCoordonnee Corrections = (DocOwner->MargeVertCp *2)
                                      + AspectY( m_PenWidthHaut)
                                      + AspectY( m_PenWidthBas);

            if( EtatOwner->Ole)
            {
                TCoordonnee hMax = EtatOwner->Hauteur
                                    - EtatOwner->CalculPlaceVoulueEnBas(BandeOwner)
                                    - BandeOwner->Top - TCoordonnee::Pix(1, Glob->ResolEcran);
                HeightSouhaiteeMin = EtatOwner->Ole->GetHauteur(TCoorPoint( EtatOwner->Largeur, hMax-Corrections), !EtatOwner->NbBandesSurLaPage,m_nLastCharPrint);

                HeightSouhaiteeMin += Corrections;

                HeightSouhaiteeMax = HeightSouhaiteeMin;
                bReturn = HeightSouhaiteeMin.Twips > CoorRc.RectTwips.Height();

            }else{
                Glob->Rtf->InitContenu( CoorRc, Font, txt, m_fPresentation, m_nLastCharPrint);
                HauteurVoulue = Glob->Rtf->Hauteur;

                if( TiensIlEstEnCours || HauteurVoulue.Twips > CoorRc.RectTwips.Height())
                {  // Va falloir étirer
                    HeightSouhaiteeMin = HauteurVoulue
                           + (TiensIlEstEnCours?TCoordonnee():CoorRc.Top-BandeOwner->Top)
                           + Corrections;
                    if( TiensIlEstEnCours)
                        HeightSouhaiteeMax = HeightSouhaiteeMin;
                    else
                        HeightSouhaiteeMax.PixelsEcran = max( HeightSouhaiteeMin.PixelsEcran,
                                                              HeightSouhaiteeMin.PixelsEcran + BandeOwner->Hauteur.PixelsEcran - (CoorRc.Bottom.PixelsEcran-BandeOwner->Top.PixelsEcran));
                    bReturn = true;
                } 
            }
        }
        return bReturn;
    }
    return false;
}
//---------------------------------------------------------------------------
void __fastcall TCpTexte::Dessine( const TBande* BandeADessiner)
{
    TCpRectangle::Dessine( BandeADessiner);
    EICFont * FontCourante = Font;
    Text_Format FormatTmp = m_Format;
    Text_Presentation PresentationTemp = m_fPresentation;
    AnsiString Txt = FormateTexte( PresentationTemp, Texte, FormatTmp, pvFormat);
    //si il y a un commentaire de saisie et que le texte est vide on applique celui-ci
    if (Txt.IsEmpty() && !Commentaire.IsEmpty())
      {
      Txt = Commentaire;
      FontCourante = FontCommentaire;
      FormatTmp = tf_Normal; //format standard pour que le commentaire s'affiche quand le champ est numérique
      PresentationTemp = m_fPresentationCommentaire;
      }

    if( (Format != tf_CadreAdm) &&
        !((Format == tf_Booleen) && ((int)pvFormat == bf_CaseACocher)) &&
        ( !m_SoulignePointille) &&
        !(m_fPresentation & Tx_FinPointilles)          &&
        Txt.IsEmpty()                  ) return;

    TCanvas *c = IsCanvasSupport();
    TCoorRect CoorRc;

    bool bDessinSpecial = m_fPresentation & Tx_Extensible || (Txt.Pos( DebutTexteRTF) == 1) || (Txt.Pos( DebutTexteOLE) == 1);
    if( GetTrueCoordonneesInternes( bDessinSpecial, CoorRc, BandeADessiner))
    {
        if( c)
        {
            c->Pen->Color = PenColor;
            c->Pen->Style = m_PenStyle;
            c->Pen->Width = m_PenWidthBas;
        }
        TComposant::CouleurDraw();
        if( bDessinSpecial)
        {
            if( EtatOwner->Ole && (Txt.Pos( DebutTexteOLE) == 1))
            {
TRACEF(  TAGL, "TCpTexte::Dessine CoorRc.Bottom-CoorRc.Top[%.2lf]", CoorRc.Bottom-CoorRc.Top);
                EtatOwner->Ole->Draw( DocOwner->Support, CoorRc, EtatOwner->Largeur, !EtatOwner->NbBandesSurLaPage, m_nLastCharPrint);
            }else{
                long nOldLastCharPrint = m_nLastCharPrint,
                     n = Glob->bConception? 0L : max( 0L, m_nLastCharPrint);
                m_nLastCharPrint = -1;
                DrawRichText( DocOwner->Support, CoorRc, Font,
                              Txt, m_fPresentation,
                              m_BrushColor, m_BrushStyle,
                              n, m_nLastCharPrint);
                if( (m_nLastCharPrint != -1) && (EtatOwner->NbBandesSurLaPage == 0) && (nOldLastCharPrint == m_nLastCharPrint))
                {
                  TRACEF(  TAGL, "Première bande de la page : on ne peut rien afficher [%s]", Txt.c_str());
                  EICAttention( "Un élément contenu dans un texte de cette page est trop grand pour y figurer correctement."
                                " Veuillez découper cet élément.");
                  m_nLastCharPrint = -1;
                }
            }
        }else{
            TCoordonnee LargeurCpEcran, HauteurCpEcran, c;
            LargeurCpEcran.PixelsEcran = CoorRc.Right.PixelsEcran - CoorRc.Left.PixelsEcran;
            HauteurCpEcran.PixelsEcran = (CoorRc.Bottom-BandeHt->Top).PixelsEcran - (CoorRc.Top-BandeHt->Top).PixelsEcran;
            if( IsPrinting())
                LargeurCpEcran.PixelsEcran = (CoorRc.Right - m_DecalInterneDroite).PixelsEcran -
                                 (CoorRc.Left - m_DecalInterneGauche).PixelsEcran;

            DrawTexte( DocOwner->Support, CoorRc.RectPixels, LargeurCpEcran, HauteurCpEcran, FontCourante, Txt, PresentationTemp, m_Orientation, FormatTmp, pvFormat, m_SoulignePointille, m_EspaceTexte.PixelsY);
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpTexte::InvalidateR( const TCoorRect &Rc)
{
    TCoorRect RcTrue;
    GetTrueCoordonnees( RcTrue);
    _Invalidate( min( RcTrue.Left,   Rc.Left  ),
                     min( RcTrue.Top,    Rc.Top   ),
                     max( RcTrue.Right,  Rc.Right ),
                     max( RcTrue.Bottom, Rc.Bottom));
}
//---------------------------------------------------------------------------
void __fastcall TCpTexte::EditKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
    if(Key == VK_ESCAPE)
        PostMessage( m_ed->Parent->Handle, WM_KEYDOWN, VK_ESCAPE, 0);
}

void __fastcall TCpTexte::OnBeginEdit( TWinControl *aOwner, int OffsetX, int OffsetY)
{
    TCoorRect Rc;
    GetTrueCoordonnees( Rc);
    m_ed = new TMemo( aOwner);

//    m_ed->AutoSize = false;
    m_ed->Left   = OffsetX + Rc.Left.PixelsX;
    m_ed->Top    = OffsetY + Rc.Top.PixelsY;
    m_ed->Width  = OffsetX + (Rc.Right.PixelsX+2) - m_ed->Left - 1;
    m_ed->Height = OffsetY + (Rc.Bottom.PixelsY+2) - m_ed->Top - 1;
    m_ed->OnKeyUp = EditKeyUp;

    m_ed->Text    = Texte;
    m_ed->Visible = true;
    m_ed->Enabled = true;
    m_ed->Parent =  aOwner;
    m_ed->SetFocus();
}
void __fastcall TCpTexte::OnEndEdit( )
{
    if( m_ed == NULL) return;

    Texte = m_ed->Text ;
    m_ed->Parent =  NULL;
    delete m_ed;
    m_ed = NULL;
    Invalidate();
    Draw();
}
//---------------------------------------------------------------------------

void   __fastcall TCpTexte::SetFont( const EICFont *f)
{

    if( f && *DocOwner->FontDefaut != *f )
    {
        if( !m_Font) m_Font = new EICFont();
        if( *f != *m_Font)
        {
            m_Font->Assign( (EICFont *)f);
            if( m_Font->Name == "MS Sans Serif") m_Font->Name = "Arial";
            Modifie( );
        }
    }
    else if( m_Font)
    {
        delete m_Font;
        m_Font = NULL;
    }

}
//---------------------------------------------------------------------------

void   __fastcall TCpTexte::SetFontCommentaire( const EICFont *f)
{

    if( f && *DocOwner->FontDefaut != *f )
    {
        if( !m_FontCommentaire) m_FontCommentaire = new EICFont();
        if( *f != *m_FontCommentaire)
        {
            m_FontCommentaire->Assign( (EICFont *)f);
            if( m_Font->Name == "MS Sans Serif") m_FontCommentaire->Name = "Arial";
            Modifie( );
        }
    }
    else if( m_FontCommentaire)
    {
        delete m_FontCommentaire;
        m_FontCommentaire = NULL;
    }

}
//---------------------------------------------------------------------------

void __fastcall TCpTexte::Nettoie( )
{
    inherited::Nettoie();
    m_nLastCharPrint = -1;
}
void __fastcall TCpTexte::AppliqueStyle( EICStyle *pStyle)
{
    EICStyle *Style = pStyle;
    if( Style || GetStyle( Style))
    {
        inherited::AppliqueStyle( Style);
        if( Style->Font) SetFont( Style->Font);
        if( Style->Presentation & (Tx_HGauche | Tx_HCentre | Tx_HDroite))
          Presentation = (Text_Presentation)((Presentation & ~(Tx_HGauche | Tx_HCentre | Tx_HDroite) ) | Style->Presentation);
    }
/*    if( (m_Format == tf_Monetaire) && EtatOwner && EtatOwner->FormatCurDefaut)
      SetpvFormat( EtatOwner->FormatCurDefaut);*/
}
void __fastcall TCpTexte::CreationFmtNum_Cur( )
{
    if( m_pvFormat) return;
    switch( m_Format)
    {
        case tf_Monetaire :
        {
            EICCurrencyFmt *c = (EICCurrencyFmt *)pvFormat;
            m_pvFormat = new EICCurrencyFmt();
            ((EICCurrencyFmt *)m_pvFormat)->Assign( *c);
        }break;
        case tf_Numerique :
        {
            EICNumberFmt *c = (EICNumberFmt *)pvFormat;
            m_pvFormat = new EICNumberFmt();
            ((EICNumberFmt *)m_pvFormat)->Assign( *c);
        }break;
    }
}


//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//----------------                IMAGE               -----------------------
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

__fastcall TCpImage::~TCpImage( )
{
    if( m_Picture) delete m_Picture;
}

__fastcall TCpImage::TCpImage( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                    :TCpRectangle( ListCp, X, Y, CaracCp)
{
    m_fEtirement  = Et_Normal;
    m_Transparent = false;
}
//---------------------------------------------------------------------------

__fastcall TCpImage::TCpImage( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                    :TCpRectangle( ListCp, f, CaracCp)
{
    bool Stocke;

    f->Lit( *((int*)&m_fEtirement));
    f->Lit( Stocke);
    if( Stocke)  f->Lit( &m_Picture);
    else
    {
        f->Lit( m_File);
    }
    if( f->FileVersion >= FILE_VERSION( 2, 10))
      f->Lit( m_Transparent);
    else
      m_Transparent = false;

}
//---------------------------------------------------------------------------

void __fastcall TCpImage::Enregistre( TFlux *f)const
{
    TCpRectangle::Enregistre( f);
    f->Ecrit( m_fEtirement);
    f->Ecrit( StockageInterne);
    if( StockageInterne)  f->Ecrit( m_Picture);
    else                  f->Ecrit( m_File);
    f->Ecrit( m_Transparent);
}

//---------------------------------------------------------------------------

void __fastcall TCpImage::Dessine( const TBande* BandeADessiner)
{
    TCoorRect CoorRc;
    try{
    GetTrueCoordonnees( CoorRc, BandeADessiner);
    if( IsRectInvalideInClip( CoorRc.RectPixels))
    {
        TCpRectangle::Dessine( BandeADessiner);
        if( m_File.IsEmpty() && !m_Picture) return;

        CoorRc.Left   = CoorRc.Left + AspectX( PenWidthGauche);
        CoorRc.Top    = CoorRc.Top + AspectY( PenWidthHaut);
        CoorRc.Right  = CoorRc.Right - AspectX( PenWidthDroit);
        CoorRc.Bottom = CoorRc.Bottom - AspectX( PenWidthBas);

        if( IsRectInvalideInClip( CoorRc.RectPixels))
        {
            TComposant::CouleurDraw();
            DrawImage( DocOwner->Support, CoorRc, DocOwner->GetTruePathOfFile( m_File), m_Picture, m_fEtirement, NULL, m_Transparent);
        }
        TComposant::Dessine( BandeADessiner);
    }
    }CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------

void __fastcall TCpImage::InvalidateR( const TCoorRect &Rc)
{
    TCoorRect RcTrue;
    GetTrueCoordonnees( RcTrue);
    _Invalidate( min( RcTrue.Left,   Rc.Left  ),
                     min( RcTrue.Top,    Rc.Top   ),
                     max( RcTrue.Right,  Rc.Right ),
                     max( RcTrue.Bottom, Rc.Bottom));
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//----------------                FLECHE              -----------------------
//---------------------------------------------------------------------------

__fastcall TCpFleche::TCpFleche( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                     :TComposant( ListCp, X, Y, CaracCp)
{
    Epaisseur.PixelsX       = 1;
    m_LargeurPointe.PixelsX = 10;
    m_HauteurPointe.PixelsY = 10;
    m_Orientation = 0;
}
//---------------------------------------------------------------------------

__fastcall TCpFleche::TCpFleche( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                     :TComposant( ListCp, f, CaracCp)
{
    m_Epaisseur.Lit( f);
    m_LargeurPointe.Lit( f);
    m_HauteurPointe.Lit( f);
    f->Lit( m_Orientation);
}
//---------------------------------------------------------------------------

void __fastcall TCpFleche::Enregistre( TFlux *f)const
{
    TComposant::Enregistre( f);
    m_Epaisseur.Enregistre( f);
    m_LargeurPointe.Enregistre( f);
    m_HauteurPointe.Enregistre( f);
    f->Ecrit( m_Orientation);
}

//---------------------------------------------------------------------------

void __fastcall TCpFleche::Dessine( const TBande* BandeADessiner)
{
    TCoorRect CoorRc;
    GetTrueCoordonnees( CoorRc, BandeADessiner);
    if( IsRectInvalideInClip( CoorRc.RectPixels))
    {
        TComposant::CouleurDraw();
        DrawFleche( DocOwner->Support, CoorRc.RectPixels,
                    PenColor, PenStyle, PenWidthGauche,
                    BrushColor, BrushStyle,
                    Epaisseur.PixelsX, m_LargeurPointe.PixelsX, m_HauteurPointe.PixelsY, m_Orientation);
        TComposant::Dessine( BandeADessiner);
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpFleche::InvalidateR( const TCoorRect &Rc)
{
    TCoorRect RcTrue;
    GetTrueCoordonnees( RcTrue);
    _Invalidate( min( RcTrue.Left,   Rc.Left  ),
                     min( RcTrue.Top,    Rc.Top   ),
                     max( RcTrue.Right,  Rc.Right ),
                     max( RcTrue.Bottom, Rc.Bottom));
}

//---------------------------------------------------------------------------
//----------------                CHAMP               -----------------------
//---------------------------------------------------------------------------
__fastcall TCpChamp::~TCpChamp( )
{
    if( DocOwner->bEnCoursDestruction) return;
    if( m_ListCpOwner->BandeOwner->EtatOwner)
        m_ListCpOwner->BandeOwner->EtatOwner->LstCpChamp->Extract( this);
}
//---------------------------------------------------------------------------

__fastcall TCpChamp::TCpChamp( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                    :TCpTexte( ListCp, X, Y, CaracCp)
{
    try{
        if( m_ListCpOwner->BandeOwner->EtatOwner)
            m_ListCpOwner->BandeOwner->EtatOwner->LstCpChamp->Add( this);
        m_Nom = EmptyStr;
        m_Donnee = EmptyStr;
        m_fType = tc_Normal;
        m_Field = NULL;
        m_bInitialise = false;
    }CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------

__fastcall TCpChamp::TCpChamp( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                    :TCpTexte( ListCp, f, CaracCp)
{
    try{
        if( m_ListCpOwner->BandeOwner->EtatOwner)
            m_ListCpOwner->BandeOwner->EtatOwner->LstCpChamp->Add( this);
        m_Field = NULL;
        m_bInitialise = false;
        f->Lit( m_Nom);
        for( int i = 0; i < DocOwner->Langue; i++)
        {
            if( TCpTexte::GetTexteLangue(i, 0) == "[" + m_Nom + "]")
                TCpTexte::SetTexteLangue(i, 0, EmptyStr);
        }

        f->Lit( *((int*)&m_fType));
/*        if( m_Format == tf_Monetaire)
            pvFormat = NULL;
        if( m_Format == tf_Numerique)
        {
            pvFormat = NULL;
            m_Format = tf_Monetaire;
        }*/
        f->Lit( m_Donnee);
        f->Lit( m_bVisible);
        if( m_fType == tc_Calcule)
        {
            f->Lit( *((int*)&m_fTypeCalcul));
            if( m_fTypeCalcul == tcalc_Colonne)
            {
                f->Lit( *((int*)&m_fTypeCalculCol));
                f->Lit( m_RuptureAssociee);
            }
        }
    }CATCH_EXCEPTION( TAGL);
}
//---------------------------------------------------------------------------

void __fastcall TCpChamp::Enregistre( TFlux *f)const
{
    TCpTexte::Enregistre( f);
    f->Ecrit( m_Nom);
    f->Ecrit( m_fType);
    f->Ecrit( m_Donnee);
    f->Ecrit( m_bVisible);
    if( m_fType == tc_Calcule)
    {
        f->Ecrit( m_fTypeCalcul);
        if( m_fTypeCalcul == tcalc_Colonne)
        {
            f->Ecrit( m_fTypeCalculCol);
            f->Ecrit( m_RuptureAssociee);
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TCpChamp::FormateValeur( )
{  
    AnsiString Txt = TCpTexte::Texte;
    if( !Txt.IsEmpty())
    {
        try{
            switch( m_Format)
            {
                case tf_Monetaire :
                case tf_Numerique :
                    if( IsValeurSignificative( Txt))
                     ;   //TCpTexte::SetTexte( Round( Txt.ToDouble(), ((EICCurrencyFmt*)pvFormat)->NumDigits) );
                    else
                        TCpTexte::SetTexte( EmptyStr);
                break;
                case tf_Date :   ;
//                    if( Txt == TDateTime())
//                    if( TDateTime( Txt) == TDateTime())
//                        TCpTexte::SetTexte( EmptyStr);
            }
        }catch(...)
        {
            TCpTexte::SetTexte( "ERREUR");
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TCpChamp::InitValeur( bool bCalcAll)
{
#if tc_Max != 4
    #error "type de champ non reconnu"
#endif
#if tcalc_Max != 3
    #error "type de calcul de champ non reconnu"
#endif
    if( !Glob->bConception &&
        (!m_bInitialise || !m_ListCpOwner->BandeOwner->EtatOwner))
    {
        AnsiString TexteBefore = TCpTexte::Texte;
        try{
            switch ( m_fType)
            {
                case tc_Normal :
                        m_bInitialise = true;
                    break;
                case tc_Programme :{
//                            TCpTexte::SetTexte( !Glob->LanceEnConception ? EmptyStr : AnsiString("[" + m_Nom + "]"));
                        if( !Glob->LanceEnConception) TCpTexte::SetTexte( EmptyStr);
                        if( DocOwner->OnChamp) if( !DocOwner->OnChamp( this)) return;
                        m_bInitialise = true;
                    }break;
                case tc_BaseDeDonnee :
/*                        if( EtatOwner->BaseDeDonnee->FieldByName( m_Donnee))
                            m_Texte = EtatOwner->BaseDeDonnee->FieldByName( m_Donnee)->AsString;
                        else
                            m_Texte = "Champ " + m_Donnee + " inexistant";*/
                        try{
                            if( !m_Field || m_Field->DataSet != EtatOwner->BaseDeDonnee)
                            {
                                m_Field = EtatOwner->BaseDeDonnee->FieldByName( m_Donnee);
                            }
                            ASSERT( AnsiSameText( m_Field->FieldName, m_Donnee));
                            TCpTexte::SetTexte( m_Field->AsString);
                        }catch(...){
                            //TCpTexte::SetTexte( "Champ " + m_Donnee + " inexistant");
                        }
                        m_bInitialise = true;
                    break;
                case tc_Calcule :
                        switch ( m_fTypeCalcul)
                        {
                            case tcalc_Info :
                                    if( Champ == NOMBRE_DE_PAGE)
                                        TCpTexte::SetTexte( EtatOwner->NumberOfPage);
                                    else if( Champ == PAGE_X_SUR_Y)
                                        TCpTexte::SetTexte( AnsiString( "Page ") + EtatOwner->CurrentPage + " / " + EtatOwner->NumberOfPage);
                                    else if( Champ == NUMERO_DE_PAGE)
                                        TCpTexte::SetTexte( EtatOwner->CurrentPage);
                                    else if( Champ == DATE)
                                        TCpTexte::SetTexte( TDateTime::CurrentDateTime().DateTimeString());
                                    else if( Champ == NOMBRE_D_ELEMENTS)
                                        TCpTexte::SetTexte( EtatOwner->BaseDeDonnee->RecordCount);

                                    //m_bInitialise = true;
                                break;
                            case tcalc_Colonne :
                                {
                                    TBande *bdDetail = EtatOwner->GetBandeDetail();
                                    if( bCalcAll ^ (bdDetail == BandeOwner))
                                    {
                                        m_bInitialise = true;
                                        switch( m_fTypeCalculCol)
                                        {
                                            case tCalcCol_Total      :
                                            case tCalcCol_Total_Page :
                                            {
                                                double d = D_NS;
                                                TField *f = EtatOwner->BaseDeDonnee?EtatOwner->BaseDeDonnee->FindField( Champ):NULL;
                                                if( f)
                                                    d = f->AsFloat;
                                                else
                                                {   // Recherche dans la bande
                                                    TCpChamp *Cp = bdDetail->GetCpChamp( Champ);
                                                    if( Cp && !Cp->Texte.IsEmpty())
                                                        d = Cp->Texte.ToDouble();
                                                }
                                                if( IsValeurSignificative( d))
                                                {

                                                    TCpTexte::SetTexte( TexteBefore.ToDouble() + d);
                                           //         TRACE( "Champ[%s][%s][%lf]", Champ.c_str(),TexteBefore.c_str(), d);
                                                }
                                            }break;
                                        }
                                    }
                                }break;
                            case tcalc_Ligne :
                                   // if( bCalcAll)
                                    {
                                        bool bChpEnCours = (EtatOwner->CpChampEnCours != NULL);
                                        AnsiString s = TCpTexte::Texte;
                                        if( !bChpEnCours)
                                            EtatOwner->CpChampEnCours = this;
                                        if( !EtatOwner->Formule->bCalcEncours)
                                        {
                                            EtatOwner->Formule->Formule = Formule;
                                            EtatOwner->Formule->Execute( s);
                                        }else
                                        {
                                            TCalculDeFormules *f = new TCalculDeFormules();
                                            f->OnError           = EtatOwner->OnErrorEvent;
                                            f->OnVariable        = EtatOwner->OnVariableEvent;
                                            f->Formule  = Formule;
                                            f->Execute( s);
                                            delete f;
                                        }
                                        TCpTexte::SetTexte( s);
                                        m_bInitialise = true;
                                        if( !bChpEnCours)
                                            EtatOwner->CpChampEnCours = NULL;
                                    }
                                break;
                        }
                    break;
            }
/*            if( !m_Texte.IsEmpty())
            {
                switch( m_Format)
                {
                    case tf_Monetaire :
                    case tf_Numerique :
                        if( (m_Texte == D_NS) || (m_Texte == Glob->asD_NS) || m_Texte.IsEmpty())
                            m_Texte = EmptyStr;
                        else
                            m_Texte = Round( m_Texte.ToDouble(), ((EICCurrencyFmt*)pvFormat)->NumDigits) ;
                            break;
                    case tf_Date :
                        if( TDateTime( m_Texte) == TDateTime())
                            m_Texte = EmptyStr;
                }
            }*/
            FormateValeur();
        }
        catch(...)
        {
//            EICErreur( "Problème lors de l'initialisation du champ " + m_Texte);
            TCpTexte::SetTexte( "ERREUR");
        }
        if( TexteBefore != TCpTexte::Texte) DocOwner->Modifie();
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpChamp::Calculs( )
{
    if( !Glob->bConception)
    {
        if( m_fType == tc_BaseDeDonnee)
        {
            try{
//                m_Field = EtatOwner->BaseDeDonnee->FieldByName( m_Donnee);
            }catch(...){
                m_Field = NULL;
            }
/*                m_Field = new TField( NULL);
            m_Field->DataSet = EtatOwner->BaseDeDonnee;
            m_Field->FieldName = m_Donnee;*/
        }
    }
}
//---------------------------------------------------------------------------
void   __fastcall TCpChamp::SetTexte( const AnsiString &Texte)
{
    if( Texte != TCpTexte::Texte)
    {
        TCpTexte::SetTexte( Texte);
        FormateValeur();
    }
    if( !Glob->bConception)
        m_bInitialise = true;
}
AnsiString __fastcall TCpChamp::GetTexte()const
{
/*    if( !Glob->bConception &&
        (!m_bInitialise || !m_ListCpOwner->BandeOwner->EtatOwner))
    {*/
        ((TCpChamp*)this)->InitValeur();
//    }
    return TCpTexte::Texte;
}
//---------------------------------------------------------------------------
void   __fastcall TCpChamp::SetVisible( bool Visible) {
    if( Visible != m_bVisible) {
        m_bVisible = Visible;       Modifie( );
    }
}
//---------------------------------------------------------------------------
void __fastcall TCpChamp::Dessine( const TBande* BandeADessiner)
{
    AnsiString s = Texte; /* permet d''initialiser m_Texte*/
    if( !Glob->bConception && !GetVisible()) return;

    EtatOwner->CpChampEnCours = this;

    Text_Format tf = m_Format;
    if( Glob->bConception && (m_fType != tc_Normal) )
    {
        m_Format = (Text_Format)((tf == tf_CadreAdm)? tf_CadreAdm : tf_Normal);
        Glob->bConception = false;
        TCpTexte::SetTexte( "[" + m_Nom + "]");
        Glob->bConception = true;
    }else if( Glob->LanceEnConception && (m_Format == tf_Booleen))
    {
        TCpTexte::SetTexte( "Oui");
    }else
        TCpTexte::SetTexte( Texte);
    TCpTexte::Dessine( BandeADessiner);
    if( Glob->bConception)
    {
        m_Format = tf;
        Glob->bConception = false;
        TCpTexte::SetTexte( s);
        Glob->bConception = true;
    }else if( Glob->LanceEnConception && (m_Format == tf_Booleen))
        TCpTexte::SetTexte( s);

    EtatOwner->CpChampEnCours = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TCpChamp::Nettoie( )
{
    try{
        inherited::Nettoie();
        m_Field = NULL;
        m_bInitialise = false;
        switch ( m_fType)
        {
            case tc_Normal : break;
            case tc_Programme :    if( Glob->bConception) {TCpTexte::SetTexte( "[" + m_Nom + "]"); break;}
            case tc_BaseDeDonnee : TCpTexte::SetTexte( EmptyStr); break;
            case tc_Calcule :
                    switch ( m_fTypeCalcul)
                    {
                        case tcalc_Info :
                                if( Champ == NOMBRE_DE_PAGE)         TCpTexte::SetTexte( "0");
                                else if( Champ == PAGE_X_SUR_Y)      TCpTexte::SetTexte( "");
                                else if( Champ == "Numéro de page")  TCpTexte::SetTexte( "0");
                                else if( Champ == DATE)              TCpTexte::SetTexte( "0//0//0");
                            break;
                        case tcalc_Colonne :
                                if( EtatOwner->GetBandeDetail() == BandeOwner)
                                {
                                    switch( m_fTypeCalculCol)
                                    {
                                        case tCalcCol_Total      :
                                        case tCalcCol_Total_Page :       TCpTexte::SetTexte( "0");
                                        break;
                                    }
                                }
                            break;
                        case tcalc_Ligne :
                                TCpTexte::SetTexte( "");
                            break;
                    }
                    break;
        }
    }catch(...)
    {
        TCpTexte::SetAllTextes( EmptyStr);
    }
}

//---------------------------------------------------------------------------
//----------------               TABLEAU              -----------------------
//---------------------------------------------------------------------------
__fastcall TCpTableau::~TCpTableau( )
{
    m_bEnCours = true;
    ColonnesClear();
    delete m_Colonnes; m_Colonnes = NULL;
    LignesClear();
    delete m_Lignes; m_Lignes = NULL;
}
//---------------------------------------------------------------------------

__fastcall TCpTableau::TCpTableau( TListOfComposants *ListCp, const TCoordonnee &X, const TCoordonnee &Y, Carac_Composant CaracCp)
                      :TCpRectangle( ListCp, X, Y, CaracCp)
{
    m_bEnCours = false;
    m_Colonnes = new TList();
    m_Lignes = new TList();
    m_Nom = EmptyStr;
    m_PenWidthLine = 0.75;
    Modifie();
}
//---------------------------------------------------------------------------

__fastcall TCpTableau::TCpTableau( TListOfComposants *ListCp, TFlux *f, Carac_Composant CaracCp)
                      :TCpRectangle( ListCp, f, CaracCp)
{
    try{
        int nbCol;
        double LargeurPourCent;
        m_bEnCours = true;
        m_bInitialized = false;
        m_Colonnes = new TList();
        m_Lignes = new TList();
        f->Lit( m_Nom);
        f->Lit( m_bVisible);
        f->Lit( m_PenWidthLine);
        if( f->FileVersion >= FILE_VERSION( 1, 9))
            f->Lit( nbCol);
        else nbCol = 0;
        SetNbLignes( nbCol);
        f->Lit( nbCol);

        for( int i = 0; i < nbCol; i++)
        {
            COLONNE *c = new COLONNE();
            c->nOrdreAffichage = m_Colonnes->Add( c);
            c->Visible         = true;
            if( f->FileVersion <= FILE_VERSION( 0, 6))
            {
                int n;
                f->Lit( n);
                c->LargeurSaisie.DixMm = ::MulDiv( m_PointBsD.x.DixMm - m_PointHtG.x.DixMm, n, 100);
            }else
                c->LargeurSaisie.Lit( f);

            if( f->FileVersion >= FILE_VERSION( 1, 7))
            {
                c->LargeurMin.Lit( f);
                c->LargeurMax.Lit( f);
            }
        }
    }CATCH_EXCEPTION( TAGL);
    m_bEnCours = false;
}
//---------------------------------------------------------------------------

void __fastcall TCpTableau::Enregistre( TFlux *f)const
{
    TCpRectangle::Enregistre( f);
    f->Ecrit( m_Nom);
    f->Ecrit( m_bVisible);
    f->Ecrit( m_PenWidthLine);
    f->Ecrit( m_Lignes->Count);
    f->Ecrit( m_Colonnes->Count);
    for( short i = 0; i < m_Colonnes->Count; i++)
    {
        COLONNE *c = GetColonne( i, false);
        c->LargeurSaisie.Enregistre( f);
        c->LargeurMin.Enregistre( f);
        c->LargeurMax.Enregistre( f);
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpTableau::InitValeur( bool bCalcAll)
{
//    if( !Glob->bConception)
    {
        try{
//            DocOwner->FixeNonModifie();
//            if( DocOwner->OnTableau)
//                DocOwner->OnTableau( this);
//            if( DocOwner->Modified)
//                ReCalculColonnesLignes();
        }
        catch(ETropDeColonnes &e){throw;}
        catch(...){}
    }
}
//---------------------------------------------------------------------------

void __fastcall TCpTableau::Dessine( const TBande* BandeADessiner)
{
    if( Glob->bConception || GetVisible())
    {
        TCoorRect CoorRc;
        GetTrueCoordonnees( CoorRc, BandeADessiner);
        if( IsRectInvalideInClip( CoorRc.RectPixels))
        {
            bool bDessineHaut = (BandeADessiner==BandeOwner),
                 bDessineBas = (BandeADessiner==BandeBs);
            TComposant::CouleurDraw();
            DrawTableau( DocOwner->Support, CoorRc, RayonCourbure.PixelsX,
                         m_BrushColor, m_BrushStyle, PenColor, m_PenStyle,
                         m_PenWidthGauche, bDessineHaut?m_PenWidthHaut:0,
                         m_PenWidthDroit, bDessineBas?m_PenWidthBas:0,
                         m_Colonnes, m_PenWidthLine, m_Lignes);
            TComposant::Dessine( BandeADessiner);
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TCpTableau::Nettoie( )
{
    inherited::Nettoie();
    m_bInitialized = false;
}
//---------------------------------------------------------------------------
void __fastcall TCpTableau::ColonnesClear()
{
    if( !m_bEnCours)
        EtatOwner->InvalideComposantsAttacheA( m_Nom);

    m_bInitialized = false;
    for( int i = 0; i < m_Colonnes->Count; i++)
        delete (COLONNE*)m_Colonnes->Items[i];
    m_Colonnes->Clear();

    if( !m_bEnCours)
        Modifie();
}
//---------------------------------------------------------------------------
void __fastcall TCpTableau::LignesClear()
{
    if( !m_bEnCours)
        EtatOwner->InvalideComposantsAttacheA( m_Nom);

    m_bInitialized = false;
    for( int i = 0; i < m_Lignes->Count; i++)
        delete (COLONNE*)m_Lignes->Items[i];
    m_Lignes->Clear();

    if( !m_bEnCours)
        Modifie();
}
//---------------------------------------------------------------------------
void  __fastcall TCpTableau::AddColonne( const TCoordonnee &LargeurSaisie, const TCoordonnee &LargeurMin, const TCoordonnee &LargeurMax)
{
    COLONNE *c = new COLONNE();
    c->nOrdreAffichage = m_Colonnes->Add( c);
    c->Visible       = true;
    c->LargeurSaisie = LargeurSaisie;
    c->LargeurMin = LargeurMin;
    c->LargeurMax = LargeurMax;
    EtatOwner->NettoieComposantsAttacheA( m_Nom);
    Modifie();
}
//---------------------------------------------------------------------------
short __fastcall TCpTableau::GetColonneCount( )const
{
    return m_Colonnes->Count;
}
//---------------------------------------------------------------------------
COLONNE* __fastcall TCpTableau::GetColonne( short index, bool bRecalcul)const
{
    if( index > m_Colonnes->Count-1)
        return NULL;
//    if( bRecalcul)
//        ((TCpTableau*)this)->ReCalculColonnesLignes();
    return (COLONNE*)m_Colonnes->Items[index];
}
//---------------------------------------------------------------------------
TCoordonnee __fastcall TCpTableau::GetGaucheColonne( short index, bool ForceCanvasResol)const
{
    if( index > m_Colonnes->Count) return -10;
    bool bPushResol = false;
    if( ForceCanvasResol && IsPushedResolution()) {PopResolution(); bPushResol = true;}

    TCoordonnee LigneGauche, Gauche;
    if( index)
        LigneGauche = AspectX( m_PenWidthLine);
    else
        LigneGauche = AspectX( m_PenWidthGauche);
    TCoordonnee c = TCoordonnee::PixX( ((COLONNE*)m_Colonnes->Items[index])->GaucheCalc.PixelsX + LigneGauche.PixelsX);
    if( bPushResol) PushResolutionAndPutEcran();
    return c;
}
//---------------------------------------------------------------------------
TCoordonnee  __fastcall TCpTableau::GetDroiteColonne( short index, bool ForceCanvasResol)const
{
    if( index > m_Colonnes->Count) return -10;
    bool bPushResol = false, bDernColVisible = true;
    if( ForceCanvasResol && IsPushedResolution()) {PopResolution(); bPushResol = true;}

    TCoordonnee Lignes, Droit;
    for( int i = index+1; bDernColVisible && i < m_Colonnes->Count; i++)
    {
        bDernColVisible = !((COLONNE*)m_Colonnes->Items[i])->Visible;
    }

    if( bDernColVisible)//index == m_Colonnes->Count-1)
        Lignes.PixelsX = AspectX( m_PenWidthDroit).PixelsX;
    else
        Lignes.PixelsX = 1;

    Droit = ((COLONNE*)m_Colonnes->Items[index])->GaucheCalc +
            ((COLONNE*)m_Colonnes->Items[index])->LargeurCalc;
    TCoordonnee c = TCoordonnee::PixX( Droit.PixelsX - Lignes.PixelsX);
    if( bPushResol) PushResolutionAndPutEcran();
    return c;
}
//---------------------------------------------------------------------------
void   __fastcall TCpTableau::Calculs( )
{
    if( m_Colonnes)
    {
//        InitValeur();
/*        TCoorRect CoorRc;
        GetTrueCoordonnees( CoorRc, NULL);
        CalcCoorColonne( CoorRc, m_Colonnes,
                         m_PenWidthGauche, m_PenWidthDroit, m_PenWidthLine);
        m_bInitialized = true;*/
    }
}
//---------------------------------------------------------------------------
void __fastcall TCpTableau::ReCalculColonnesLignes( const TCoorRect &CoorRc)
{
    if( (m_Colonnes ||m_Lignes)&& !m_bInitialized)
    {
        if( DocOwner->OnTableau)
            DocOwner->OnTableau( this);
//        TCoorRect CoorRc;
//        GetTrueCoordonnees( CoorRc);
        if( m_Colonnes) CalcCoorColonne( CoorRc, m_Colonnes, m_PenWidthLine);
        if( m_Lignes)   CalcCoorLigne( CoorRc, m_Lignes, m_PenWidthLine);
        m_bInitialized = true;
    }
}
void __fastcall TCpTableau::GetTrueCoordonnees( TCoorPoint &ptHtG, TCoorPoint &ptBsD, const TBande* BandeADessiner)const
{
    bool b = (LARGEUR_SANS_MARGE_GAUCHE != m_LargTrueCoor);
    inherited::GetTrueCoordonnees( ptHtG, ptBsD, BandeADessiner);
    TCoorRect CoorRc; CoorRc.TopLeft = ptHtG; CoorRc.BottomRight = ptBsD;
    if( (m_Colonnes ||m_Lignes)&& m_bInitialized && b)
    {
        if( m_Colonnes) CalcCoorColonne( CoorRc, m_Colonnes, m_PenWidthLine);
        if( m_Lignes)   CalcCoorLigne( CoorRc, m_Lignes, m_PenWidthLine);
    }else
        ((TCpTableau*)this)->ReCalculColonnesLignes( CoorRc);
    if( m_Colonnes && m_Colonnes->Count)
    {
        TCoordonnee LargTot;
//        LargTot.Pixels = AspectX( m_PenWidthGauche).PixelsX + AspectX( m_PenWidthDroit).PixelsX;
        for(int i = 0; i < m_Colonnes->Count; i++)
        {
            LargTot += ((COLONNE*)m_Colonnes->Items[i])->LargeurCalc;
        }
        if( LargTot < ptBsD.x - ptHtG.x)
        {
            ptHtG.x = ptHtG.x + (ptBsD.x - ptHtG.x - LargTot) / 2;
            ptBsD.x = ptHtG.x + LargTot;
            CoorRc.TopLeft = ptHtG; CoorRc.BottomRight = ptBsD;
            if( m_Colonnes) CalcCoorColonne( CoorRc, m_Colonnes, m_PenWidthLine);
            if( m_Lignes)   CalcCoorLigne( CoorRc, m_Lignes, m_PenWidthLine);
        }
    }
}

void __fastcall TCpTableau::GetLigne( short index, TCoordonnee &cHaut, TCoordonnee &cBas)const
{
//    ((TCpTableau*)this)->ReCalculColonnesLignes();
    TCoorRect CoorRc;
    GetTrueCoordonnees( CoorRc);
    bool bPushResol = false;
    if( IsPushedResolution()) {PopResolution(); bPushResol = true;}

    TCoordonnee LigneHaut;
    if( index)
        LigneHaut = AspectX( m_PenWidthLine);
    else
        LigneHaut = AspectX( m_PenWidthHaut);

    if( BandeHt != BandeBs || !m_Lignes->Count)
    {
        ASSERT( FALSE);
        cHaut = CoorRc.Top;
        cBas = CoorRc.Bottom;
    }else
    {
        cHaut = TCoordonnee::PixX( ((LIGNE*)m_Lignes->Items[index])->HautCalc.PixelsY + LigneHaut.PixelsX);
        cBas  = TCoordonnee::PixX( ((LIGNE*)m_Lignes->Items[index])->BasCalc.PixelsY-1);
    }
    if( bPushResol) PushResolutionAndPutEcran();
}
void   __fastcall TCpTableau::SetNbLignes( short s)
{
    if( s != m_Lignes->Count)
    {
        m_bInitialized = false;
        if( m_Lignes->Count > s)
        {
            for( int i = m_Lignes->Count - s; i > 0 ; i--)
                m_Lignes->Delete( 0);
        }else
        {
            for( int i = s - m_Lignes->Count; i > 0; i--)
                m_Lignes->Add( new LIGNE());
        }
        if( EtatOwner)
          EtatOwner->InvalideComposantsAttacheA( m_Nom);
        Modifie();
    }
}
bool   __fastcall TCpTableau::GetVisible( )const
{
    bool b = inherited::GetVisible();
    if( b && m_Colonnes->Count)
    {
        bool bColVisible = false;
        for( int i = 0; !bColVisible && i < m_Colonnes->Count; i++)
            bColVisible = ((COLONNE*)m_Colonnes->Items[i])->Visible;
        if( !bColVisible) b = false;
    }
    return b;
}

